美文网首页
强制横屏大全

强制横屏大全

作者: zhong_JF | 来源:发表于2016-10-25 11:55 被阅读0次

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

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参考)

相关文章

  • 强制横屏大全

    最近做直播,竖屏的项目需要支持横屏,经过各种恶心的深坑,搜集的大全 1.在APPDelegate添加项目支持方向,...

  • iOS:强制横屏的坑

    前段时间我们播放器强制横屏,项目设置允许竖屏,在手机不锁屏状态下,手机横屏会导致播放器强制横屏的时候会导致横屏失败...

  • iOS强制横屏

    iOS强制横屏

  • 强制横屏方法

    强制横屏: 方法一: 关于强制横屏看了很多文章,首先第一个方法是invocation,这个方法可以实现横屏效果,但...

  • 强制横屏

    转载自 :http://blog.csdn.net/zhaotao0617/article/details/525...

  • 强制横屏

    -(void)landscapeAndPortraitChange{UIInterfaceOrientation ...

  • 强制横屏

    1、AppDelegate里设置属性 @property(nonatomic,assign)BOOLallowLa...

  • iOS强制横屏方法之一

    //这段代码是强制产生横屏效果,通过kvo实现//强制右横屏 可以过审核-(void)viewWillAppea...

  • 横竖屏

    需求: 让push的ViewController界面强制横屏 一、配置 二、添加强制横屏方法 pragma mar...

  • iOS 屏幕旋转控制

    /** 屏幕旋转控制 allowRotateType ==(0强制竖屏,1横竖屏,2~强制横屏 )*/ (UIIn...

网友评论

      本文标题:强制横屏大全

      本文链接:https://www.haomeiwen.com/subject/pqeruttx.html