iOS中屏幕旋转问题解决

https://blog.csdn.net/black_house/article/details/42460127

竖屏点击按钮 旋转到横屏
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];//这句话是防止手动先把设备置为横屏,导致下面的语句失效.
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];

横屏点击按钮, 旋转到竖屏
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];//这句话是防止手动先把设备置为竖屏,导致下面的语句失效.
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];

同时还要必须支持自动旋转
- (BOOL)shouldAutorotate
{
    return YES;
}

然后就是
- (NSUInteger)supportedInterfaceOrientations
{
    if (IS_IPHONE && self.isHalfScreen) { //如果是iPhone,且为竖屏的时候, 只支持竖屏
        return UIInterfaceOrientationMaskPortrait;
    }
    return UIInterfaceOrientationMaskLandscape; //否者只支持横屏
}

猜你喜欢

转载自blog.csdn.net/jeffasd/article/details/82420047