2009-12-29 35 views
0

在UIScrollView中,我有一個UIImageView,並將contentMode設置爲Aspect Fill。當我將模擬器旋轉到橫向模式時,UIImageView顯示圖像的中心,我無法向上滾動以查看整個圖像。UIScrollView在橫向模式下使用Aspect Fill

我該如何解決這個問題,以便當我旋轉iPhone時,我會看到圖像的頂部(但仍然使用Aspect Fill進行縮放)。

回答

0

需要設置的幀的大小:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    CGFloat ratio = imageView.frame.size.width/imageView.image.size.width; 
    CGRect rect = CGRectMake(0, 0, imageView.frame.size.width , ratio*imageView.image.size.height); 
    [scrollView setContentSize:rect.size]; 
    [imageView setFrame:CGRectMake(0.0f, 0.0f, rect.size.width, rect.size.height)]; 
}