Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 无法将imageview定位到中心_Iphone_Objective C_Ios_Imageview_Zooming - Fatal编程技术网

Iphone 无法将imageview定位到中心

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

我调用了ViewWillDisplay中的conterScrollViewContents方法,但imageView不会定位到scrollView的中心


有什么问题吗

您的代码对我来说似乎是正确的。您是否尝试调试这些值?或者您没有在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;
}