iOS的横竖屏切换旋转(禁自动旋转)
这次做了视频的播放器,坑啊 ,好多,这不,刚刚爬上来,就来帮后来者填坑。。。
@property (nonatomic, assign) NSInteger rotateDirection;
//此方法会在设备横竖屏变化的时候调用
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.rotateDirection == 1)
{
return UIInterfaceOrientationMaskLandscapeRight; // 支持右屏旋转
}
return UIInterfaceOrientationMaskPortrait;
}
3. 好了,在appdelegate中就写上这个了,是不是很简单呢
- (void)fullScreenWithPlayerView:(XYVideoPlayerView *)videoPlayerView
{
HYAppDelegate *appdelegate = ((HYAppDelegate *)[[UIApplication sharedApplication] delegate]);
if (appdelegate.rotateDirection == 0)
{
appdelegate.rotateDirection = 1;
NSLog(@" orientation1 : %ld",[UIDevice currentDevice].orientation);
if ([UIDevice currentDevice].orientation != 1)
{
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}
NSLog(@" orientation2 : %ld",[UIDevice currentDevice].orientation);
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeRight]
forKey:@"orientation"];
NSLog(@" orientation3 : %ld",[UIDevice currentDevice].orientation);
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
self.playerView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight); // 顺便改下播放器的UI
}
else
{
appdelegate.rotateDirection = 0;
NSLog(@" orientation1 : %ld",[UIDevice currentDevice].orientation);
if ([UIDevice currentDevice].orientation != 4)
{
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeRight]
forKey:@"orientation"];
}
NSLog(@" orientation2 : %ld",[UIDevice currentDevice].orientation);
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait]
forKey:@"orientation"];
NSLog(@" orientation3 : %ld",[UIDevice currentDevice].orientation);
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
self.playerView.frame = CGRectMake(0, 20, ScreenWidth, ScreenWidth / 16 * 9); // 顺便改下播放器的UI
}
}
iOS的横竖屏切换旋转(禁自动旋转)相关推荐
- iOS 中横竖屏切换
iOS 中横竖屏切换的功能,在开发iOS app中总能遇到.以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰到了,demo尝试了几种情况,这里就做下总结. 注意 横屏两种情况是反的你知道吗? U ...
- iOS终极横竖屏切换解决方案
大家的项目都是只支持竖屏的吧?大多数朋友(这其中当然也包括博主),都没有做过横屏开发,这次项目刚好有这个需求,因此把横竖屏相关的心得写成一遍文章供诸位参考. 01.综述 大多数公司的项目都只支持竖屏, ...
- iOS视频播放横竖屏切换技巧
一.需求:横竖屏切换. 二.效果: 三.实现: 如上图,点击工具栏的第四个按钮进行横屏切换: - (void)toolTabButtonPressed:(A ...
- [贝聊科技] iOS 终极横竖屏切换解决方案
大家的项目都是只支持竖屏的吧?大多数朋友(这其中当然也包括博主),都没有做过横屏开发,这次项目刚好有这个需求,因此把横竖屏相关的心得写成一遍文章供诸位参考. 01.综述 大多数公司的项目都只支持竖屏, ...
- iOS 6横竖屏切换
iOS6.0版本之前,UIViewController之间的横竖屏切换,只需设置一个函数: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInte ...
- iOS应用横竖屏切换
一.概述: 在iOS应用中,由UIViewController来控制屏幕翻转,根据需要随设备方向自动切换.在iOS6和之前的系统之间,控制方法发生了些变化. 二.视图伸缩属性: 1.UIVie ...
- ios 旋转屏幕试图切换_iOS屏幕横竖屏切换
iOS屏幕横竖屏切换 胡东东博客 • 2020 年 10 月 25 日 搜了网上的教程是真的乱,废话不多说,这里从启动到具体的VC,横竖屏切换完美搞定. 如果你的app只需要支持一个方向,那么不需要看 ...
- android 横竖屏幕切换,Android 横竖屏切换总结
一.Android切换横竖屏 应用的横竖屏设置 应用的横竖屏设置主要是通过Activity的screenOrientation属性控制,属性值如下: 主要有以下两种方式设置screenOrientat ...
- widget中自动横竖屏切换时的问题
首页 Android开发者社区 Android百科 极客学院 开启辅助访问 打卡签到 我要上头条 如何赚e币 注册验证问题 版主申请 切换到宽版 帐号 自动登录 找回密码 密码 登录 加入eoe ...
最新文章
- LeetCode简单题之石头与宝石
- Pandas (GeoPandas)笔记:set_index reset_index
- getElementById和querySelector区别
- Angular JS (2)
- [Leetcode][第117题][JAVA][填充每个节点的下一个右侧节点指针][BFS]
- java ioutils_java – 无法解析符号’IOUtils’
- python的进程和线程_Python进程与线程知识
- Ubuntu 16.04安装Bless十六进制编辑器
- 标记区域 Region
- C语言dos游戏编程,◣电脑游戏编程入门 (DOS)◥
- wenbao与cf整数直角三角形
- Atitit SpringCache缓存使用 艾提拉 attilax总结 1. Spring的抽象已经做得够好了,适合于大多数场景,非常复杂的就需要自己AOP实现了。	1 1.1. 设置配置文件支持
- 不同手指戴戒指时的清热解毒的清是什么意思?_百度知道
- 计算机 控制面板都打不开怎么办,控制面板打不开怎么办?控制面板打开办法大全...
- MySQL备份的几种常用方法与恢复步骤
- sessionStorage 、localStorage 和 cookie
- 一大波苹果CMS系统主题来袭
- 毒你没商量!DOC病毒原理完全解析(转)
- Keil5 编译时显示..\OBJ\TPAD.axf: error: L6002U: Could not open file ..\obj\main.o: No such file or direct
- DTI预处理及确定性纤维束追踪
热门文章
- 期末Django项目实训报告
- 新研究发现:太平洋上仅存的冰川将很快融化
- error LNK2038: 检测到“RuntimeLibrary”的不匹配项的解决办法
- pcd、jpg、raw、txt、二进制文件的读写操作
- POJ3621 Sightseeing Cows 分数规划 SPFA求最小环
- Python入门之元组-元组的定义和操作
- docker学习进阶之Swarm(三)
- 用scrapy+selenium + phantomjs 爬取vip网页,保存为json格式,写入到mysql数据库,下载图片(二)
- TCP|Android上TCP通信实现
- CSS笔记(八)盒子模型-----定位