중심

2012-07-08 9 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 방법이라고하지만, 이미지 뷰가있는 ScrollView의 중심에 위치하지 않습니다.중심

무엇이 문제입니까?

답변

0

코드가 맞는 것 같습니다. 값을 디버깅하려고 했습니까? 또는 인터페이스 빌더에서 imageView 변수를 연결하지 않았습니까?

+0

감사합니다. 나는이 문제를 해결했습니다. imageView의 대리자를 설정하지 않았습니다. – Weizhi