2010-01-03 90 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