2012-07-08 49 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

相關問題