问题解决了, 还算完美. 方法基本道理还是一样, 强制调用系统的自动旋转机制. 竖屏点击按钮 旋转到横屏 [[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; //否者只支持横屏 } 这里基本就可以了.
|
|