设备旋转时如何缩放UIImageView?

问题描述:

我希望当我旋转设备时,我的UIImageView变成全屏。我怎样才能做到这一点?设备旋转时如何缩放UIImageView?

+0

如果是前全屏幕,你想保持这种方式,设置相应的自动调整大小面具(你可以做到这一点无论是'autoresizingMask'或在Interface Builder)。如果不是,您可以在'willAnimateRotationToInterfaceOrientation'中更改它的框架,或在'viewWillLayoutSubviews'中的iOS 5 +中更改它。 – Rob 2012-08-10 07:37:12

在视图控制器实现willAnimateRotationToInterfaceOrientation:...和设置所需的帧为图像视图,取决于取向:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation) { 
     self.imageView.frame = ... 
    } else { 
     self.imageView.frame = ... 
    } 
} 

设置uiimageview.frame等于widow.view.frame,并选择规模以适应模式

而且不要忘了你的autoresizingMask设置为这样的事情:

self.imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 

如果你那样做,你不自己不必关心框架调整。

欢呼