Iphone 无法将imageview定位到中心
我调用了ViewWillDisplay中的conterScrollViewContents方法,但imageView不会定位到scrollView的中心Iphone 无法将imageview定位到中心,iphone,objective-c,ios,imageview,zooming,Iphone,Objective C,Ios,Imageview,Zooming,我调用了ViewWillDisplay中的conterScrollViewContents方法,但imageView不会定位到scrollView的中心 有什么问题吗 您的代码对我来说似乎是正确的。您是否尝试调试这些值?或者您没有在Interface Builder中链接imageView变量?谢谢您的回答,我刚刚解决了这个问题。我尚未设置imageView的委托。 - (void)centerScrollViewContents { CGSize boundsSize = self.s
有什么问题吗 您的代码对我来说似乎是正确的。您是否尝试调试这些值?或者您没有在Interface Builder中链接imageView变量?谢谢您的回答,我刚刚解决了这个问题。我尚未设置imageView的委托。
- (void)centerScrollViewContents {
CGSize boundsSize = self.scrollView.bounds.size;
CGRect contentsFrame = self.imageView.frame;
if (contentsFrame.size.width < boundsSize.width) {
contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0f;
} else {
contentsFrame.origin.x = 0.0f;
}
if (contentsFrame.size.height < boundsSize.height) {
contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0f;
} else {
contentsFrame.origin.y = 0.0f;
}
self.imageView.frame = contentsFrame;
}