2010-01-03 108 views
1

我有一個UIScrollView與在IB中創建的UIImageView子視圖。第一次創建一個UIImage並將其設置爲UIImageView中的圖像時,它們都可以正常工作。如果我創建一個新的UIImage並將其設置爲UIImageView中的圖像,則該圖像將被一些(看似)隨機偏移抵消。在UIImageView UIScrollView中更改UIImage

我該如何做這項工作?

+0

看來,有必要以編程方式創建一個新的UIScrollView和UIImageView,至少這個工程。 – zaph 2010-01-03 23:07:02

回答

2

看來,這應該是爲設置新的圖像一樣簡單,但似乎作爲最低限度以下是必要的:

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預先實例化。

1

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

+0

不會。即使它是相同的圖像,我仍然會發生這種情況(我正在從磁盤加載圖像,我欺騙了圖像,使其完全相同。 – zaph 2010-01-03 22:55:26