[英]how to update contentMode of UIImageView?
在最初的UIImageView我已经将其设置为
mCurrentImageView.contentMode = UIViewContentModeLeft;
因此,如果设备旋转,我将更改contentMode,但无效。 我该如何解决?
if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight) {
mCurrentImageView.contentMode = UIViewContentModeScaleAspectFit;
}
[UIDevice方向]不返回这些方向标识符。 从文档中,该消息将返回以下内容:
typedef enum {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait,
UIDeviceOrientationPortraitUpsideDown,
UIDeviceOrientationLandscapeLeft,
UIDeviceOrientationLandscapeRight,
UIDeviceOrientationFaceUp,
UIDeviceOrientationFaceDown
} UIDeviceOrientation;
要更改内容模式,您应该在willRotate消息的视图控制器代码中执行以下操作:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
mCurrentImageView.contentMode = UIViewContentModeScaleAspectFit;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.