强制横屏(仅适用于present情景)
来源:互联网 发布:成都软件培训哪家好 编辑:程序博客网 时间:2024/06/06 10:42
设置横屏很简单,只需要勾选上这两项就可以了
但这是设置全局的横屏允许,很多时候需求是大多界面只允许竖屏,只有某个界面才需要设置横屏(例如播放视频界面等),所以这时这两项就不能勾选上,那要怎么设置横屏呢,其实很简单,当然本文的方法只适用present视图
首先在appdelegate中添加一个属性
@property (nonatomic,assign) BOOL allowRotation;
然后添加代理方法
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ if (self.allowRotation) { return UIInterfaceOrientationMaskLandscape; } return UIInterfaceOrientationMaskPortrait;}
在需要设置横屏的视图present前设置为YES
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate; delegate.allowRotation = YES;
在横屏视图dismiss前设置为NO即可恢复竖屏
随意转换横竖屏(present 视频播放时全屏转换)
//修改全局属性并调用转屏方法AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; appDelegate.allowRotation = NO; [self setNewOrientation:NO];//调用转屏代码//强制转屏- (void)setNewOrientation:(BOOL)fullscreen{ if (fullscreen) { NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown]; [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"]; NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];//横屏方向(根据需求选填) [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"]; }else{ NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown]; [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"]; NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"]; }}
1 0
- 强制横屏(仅适用于present情景)
- 仅适用于 MXML 的标签
- FCKeditor 配置、扩展 -- 仅适用于ASP.NET
- 限制物料仅适用于某些子库存
- (仅适用于新手)pomelo日记
- ios开发 present 出来的viewcontroller 强制横竖屏切换代码分享 (代码不解释)
- iOS如何present一个不知道类名的控制器时使它强制转屏
- wxWidgets:使用IP Address控件(仅适用于msw)
- win7&ubuntu全攻略(仅适用于正版win7系统)
- 折半查找法(仅适用于已排好顺序)
- iOS开发 强制竖屏。系统KVO 强制竖屏—>适用于支持各种方向屏幕启动时,竖屏展示广告
- Android 强制横屏
- ios强制横屏
- 强制横屏
- 强制横屏
- android 强制横屏
- iOS 强制横屏
- 强制横屏
- LintCode 62 搜索旋转排序数组
- python映射类型:字典---创建、更新、删除、修改等操作实例源码
- MySQL中根据if标签实现多条件模糊查询(动态SQL语句)
- Service(二)
- Android Http随笔
- 强制横屏(仅适用于present情景)
- 安卓onResume()代替EventBus刷新数据情况
- Bootstrap的引用文件
- 存储之IP SAN
- centos7中使用systemctl
- LintCode 63 搜索旋转排序数组 II
- Session分布式共享 = Session + Redis + Nginx
- java——深度解析System系统类
- 移动端弹窗