强制横屏大全

最近做直播,竖屏的项目需要支持横屏,经过各种恶心的深坑,搜集的大全 

1.在APPDelegate添加项目支持方向,需要做一个单例,因为需要全局去修改支持转的方向


解释:

#pragma mark - - orientation

// 是否支持转屏

- (BOOL)shouldAutorotate

{

return [self.selectedViewController shouldAutorotate];

}

// 返回nav栈中的最后一个对象支持的旋转方向

- (UIInterfaceOrientationMask)supportedInterfaceOrientations

{

return [self.selectedViewController supportedInterfaceOrientations];

}

// 返回nav栈中最后一个对象,坚持旋转的方向

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

return [self.selectedViewController preferredInterfaceOrientationForPresentation];

}



2.在需要转屏的时候调用

// 修改项目支持的方向

[SupportedInterfaceOrientations sharedInstance].orientationMask = UIInterfaceOrientationMaskLandscapeRight;

// 强制转屏

NSNumber *orientationUnknown = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];

[[UIDevice currentDevice] setValue:orientationUnknown forKey:@"orientation"];


可以参考我的Demo,喜欢可以点赞:https://github.com/15088138451/i-m-fly  


参考文档:http://www.jianshu.com/p/6c45fa2bb970 (BUG参考)

http://www.jianshu.com/p/5c773628caa6 (解释)

http://www.cnblogs.com/niit-soft-518/p/5611298.html (BUG参考)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容