简体   繁体   中英

how to update contentMode of UIImageView?

at initial UIImageView i have set it to

mCurrentImageView.contentMode = UIViewContentModeLeft;

so if the device rotate i will change contentMode but it had no effect. how can i fix it?

if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight) {
        mCurrentImageView.contentMode = UIViewContentModeScaleAspectFit;
    }

[UIDevice orientation] does not return those identifiers for orientation. From the documentation, that message will return the following:

typedef enum {
   UIDeviceOrientationUnknown,
   UIDeviceOrientationPortrait,
   UIDeviceOrientationPortraitUpsideDown,
   UIDeviceOrientationLandscapeLeft,
   UIDeviceOrientationLandscapeRight,
   UIDeviceOrientationFaceUp,
   UIDeviceOrientationFaceDown
} UIDeviceOrientation;

To change the content mode you should do something in the view controller code in the willRotate message:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        mCurrentImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM