这次做了视频的播放器,坑啊 ,好多,这不,刚刚爬上来,就来帮后来者填坑。。。

首先先说下横竖屏切换旋转的坑吧,,,
1. 在AppDelegate.h文件中 声明一个变量,

@property (nonatomic, assign) NSInteger rotateDirection;

2.  在AppDelegate.m文件中 加一个判断旋转函数

//此方法会在设备横竖屏变化的时候调用

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{

if (self.rotateDirection == 1)

{

return UIInterfaceOrientationMaskLandscapeRight; // 支持右屏旋转

}

return UIInterfaceOrientationMaskPortrait;

}

3. 好了,在appdelegate中就写上这个了,是不是很简单呢

接下来就是在你要旋转的那个文件里面,比如:LiveVC
就在LiveVC.m中写上手动旋转屏幕的函数:

- (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

}

}

你们会发现,执行一次有可能会旋转两次,
这是因为在没有if条件的情况下,打开控制板的自动旋转,
会导致APP本身的旋转有问题(手机横屏的情况下点击全屏不会旋转),
所以再加上if旋转一次,就可以了
有问题的可以在底下评论,每天中午会进行回复,谢谢,可转载。

iOS的横竖屏切换旋转(禁自动旋转)相关推荐

  1. iOS 中横竖屏切换

    iOS 中横竖屏切换的功能,在开发iOS app中总能遇到.以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰到了,demo尝试了几种情况,这里就做下总结. 注意 横屏两种情况是反的你知道吗? U ...

  2. iOS终极横竖屏切换解决方案

    大家的项目都是只支持竖屏的吧?大多数朋友(这其中当然也包括博主),都没有做过横屏开发,这次项目刚好有这个需求,因此把横竖屏相关的心得写成一遍文章供诸位参考. 01.综述 大多数公司的项目都只支持竖屏, ...

  3. iOS视频播放横竖屏切换技巧

    一.需求:横竖屏切换. 二.效果:                       三.实现: 如上图,点击工具栏的第四个按钮进行横屏切换: - (void)toolTabButtonPressed:(A ...

  4. [贝聊科技] iOS 终极横竖屏切换解决方案

    大家的项目都是只支持竖屏的吧?大多数朋友(这其中当然也包括博主),都没有做过横屏开发,这次项目刚好有这个需求,因此把横竖屏相关的心得写成一遍文章供诸位参考. 01.综述 大多数公司的项目都只支持竖屏, ...

  5. iOS 6横竖屏切换

    iOS6.0版本之前,UIViewController之间的横竖屏切换,只需设置一个函数: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInte ...

  6. iOS应用横竖屏切换

    一.概述:     在iOS应用中,由UIViewController来控制屏幕翻转,根据需要随设备方向自动切换.在iOS6和之前的系统之间,控制方法发生了些变化. 二.视图伸缩属性: 1.UIVie ...

  7. ios 旋转屏幕试图切换_iOS屏幕横竖屏切换

    iOS屏幕横竖屏切换 胡东东博客 • 2020 年 10 月 25 日 搜了网上的教程是真的乱,废话不多说,这里从启动到具体的VC,横竖屏切换完美搞定. 如果你的app只需要支持一个方向,那么不需要看 ...

  8. android 横竖屏幕切换,Android 横竖屏切换总结

    一.Android切换横竖屏 应用的横竖屏设置 应用的横竖屏设置主要是通过Activity的screenOrientation属性控制,属性值如下: 主要有以下两种方式设置screenOrientat ...

  9. widget中自动横竖屏切换时的问题

    首页 Android开发者社区 Android百科 极客学院 开启辅助访问 打卡签到 我要上头条 如何赚e币 注册验证问题 版主申请 切换到宽版 帐号 自动登录  找回密码 密码 登录  加入eoe ...

最新文章

  1. LeetCode简单题之石头与宝石
  2. Pandas (GeoPandas)笔记:set_index reset_index
  3. getElementById和querySelector区别
  4. Angular JS (2)
  5. [Leetcode][第117题][JAVA][填充每个节点的下一个右侧节点指针][BFS]
  6. java ioutils_java – 无法解析符号’IOUtils’
  7. python的进程和线程_Python进程与线程知识
  8. Ubuntu 16.04安装Bless十六进制编辑器
  9. 标记区域 Region
  10. C语言dos游戏编程,◣电脑游戏编程入门 (DOS)◥
  11. wenbao与cf整数直角三角形
  12. Atitit SpringCache缓存使用 艾提拉 attilax总结 1. Spring的抽象已经做得够好了,适合于大多数场景,非常复杂的就需要自己AOP实现了。 1 1.1. 设置配置文件支持
  13. 不同手指戴戒指时的清热解毒的清是什么意思?_百度知道
  14. 计算机 控制面板都打不开怎么办,控制面板打不开怎么办?控制面板打开办法大全...
  15. MySQL备份的几种常用方法与恢复步骤
  16. sessionStorage 、localStorage 和 cookie
  17. 一大波苹果CMS系统主题来袭
  18. 毒你没商量!DOC病毒原理完全解析(转)
  19. Keil5 编译时显示..\OBJ\TPAD.axf: error: L6002U: Could not open file ..\obj\main.o: No such file or direct
  20. DTI预处理及确定性纤维束追踪

热门文章

  1. 期末Django项目实训报告
  2. 新研究发现:太平洋上仅存的冰川将很快融化
  3. error LNK2038: 检测到“RuntimeLibrary”的不匹配项的解决办法
  4. pcd、jpg、raw、txt、二进制文件的读写操作
  5. POJ3621 Sightseeing Cows 分数规划 SPFA求最小环
  6. Python入门之元组-元组的定义和操作
  7. docker学习进阶之Swarm(三)
  8. 用scrapy+selenium + phantomjs 爬取vip网页,保存为json格式,写入到mysql数据库,下载图片(二)
  9. TCP|Android上TCP通信实现
  10. CSS笔记(八)盒子模型-----定位