首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更新UIImageView的contentMode?

如何更新UIImageView的contentMode?
EN

Stack Overflow用户
提问于 2010-06-03 18:58:59
回答 1查看 3.2K关注 0票数 1

在初始UIImageView中,我将其设置为

代码语言:javascript
复制
mCurrentImageView.contentMode = UIViewContentModeLeft;

因此,如果设备旋转,我将更改contentMode,但它没有任何影响。我怎么才能修复它?

代码语言:javascript
复制
if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight) {
        mCurrentImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-06-03 21:43:45

UIDevice orientation不返回方向的那些标识符。从文档中,该消息将返回以下内容:

代码语言:javascript
复制
typedef enum {
   UIDeviceOrientationUnknown,
   UIDeviceOrientationPortrait,
   UIDeviceOrientationPortraitUpsideDown,
   UIDeviceOrientationLandscapeLeft,
   UIDeviceOrientationLandscapeRight,
   UIDeviceOrientationFaceUp,
   UIDeviceOrientationFaceDown
} UIDeviceOrientation;

要更改内容模式,您应该在willRotate消息中的视图控制器代码中执行一些操作:

代码语言:javascript
复制
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        mCurrentImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2965256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档