2012-07-08 43 views
0
- (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; 
} 

我在viewWillAppear中调用了conterScrollViewContents方法,但imageView不会定位到scrollView的中心。无法将imageview放置到中心

有什么问题?

回答

0

您的代码似乎对我正确。您是否尝试调试这些值?或者你可能没有在Interface Builder中链接imageView变量?

+0

谢谢你的回答,我刚解决了这个问题。我没有设置imageView的代表。 – Weizhi 2012-07-08 03:16:15

相关问题