views:

234

answers:

1

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;
    }
+1  A: 

[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;
    }
}
rickharrison
thank you rickharrison
RAGOpoR
No problem. Feel free to upvote my answer if it worked for you.
rickharrison