簡體   English   中英

在UIScrollView的UIImageView中更改UIImage

[英]changing UIImage in UIImageView in UIScrollView

我有一個UIScrollView和一個在IB中創建的UIImageView子視圖。 第一次創建UIImage並將其設置為UIImageView中的圖像時,一切正常。 如果我創建一個新的UIImage並將其設置為UIImageView中的圖像,則該圖像將偏移一些(看似)隨機偏移量。

我該如何進行這項工作?

似乎這與設置新圖像一樣容易,但似乎至少需要以下幾點:

imageScrollView.transform = CGAffineTransformIdentity;
imageScrollView.contentOffset = CGPointZero;
imageScrollView.contentSize = self.imageScrollView.frame.size;

[imageScrollView removeFromSuperview];
imageView = [[TapDetectingImageView alloc] initWithImage:newImage];

[imageScrollView addSubview: imageView];

其中imageScrollView,imageScrollView和newImage先前已實例化。

第二張圖像的長寬比是否與第一張不同? 如果是這樣,請查看UIImageView的contentMode屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM