简体   繁体   中英

iphone - On orientation change of iphone , rotate only one control and not all others

I'm having UIImageView, few lables, buttons etc in a view. Currently I have implementation for portrait mode. When orientation of iphone is changed, I just want to rotate only image view. Rest all other controls should not change. How can I implement the rotation of only image view?

I had to do something very similar recently. What I did was disable auto rotation and then used the device notifications like this:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];

- (void)didRotate:(NSNotification *)notification {  
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    switch (orientation) {
        case UIDeviceOrientationUnknown:
        case UIDeviceOrientationFaceUp:
        case UIDeviceOrientationFaceDown:
            return;
            break;
    }

    // Do something
}

You will need to handle some situations like quick rotations etc. Let me know if you need more info.

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