iOS开发屏幕旋转锁定横竖屏解决方法
第一步:配置为竖屏。禁用其他方向。如图示:
第二步:在viewDidLoad方法中用以下方法
//说明:不是真正的旋转屏幕,只旋转当前的View
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
CGRect frame = [UIScreen mainScreen].applicationFrame;
self.view.bounds = CGRectMake(0, 0, frame.size.height, frame.size.width);
(以上代码说明:理解为假旋转,不是改变 UIDevice 的 orientation,利用 CGAffineTransformMakeRotation 改变的是self.view的 transform来达到横屏的效果)