文章标题
来源:互联网 发布:远方光电人工智能 编辑:程序博客网 时间:2024/05/19 15:23
iOS总体竖屏,部分横屏问题
转载自:ht tp://blog.csdn.net/oiken/article/details/48783417
iOS零碎(90)
目录(?)[+]
参考我转载的文章 iOS 全局禁止横屏,但UIWebView 全屏横屏播放视频的解决办法
我本身项目时用FFMpeg + kxmovie 来播放视频
实现为如下:
1,AppDelegate 类添加参数,控制旋屏
// AppDelegate.h
#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@property (nonatomic, assign) BOOL allowRotation;/*** 是否允许横屏的标记 */@end
// AppDelegate.m
实现协议的函数
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {//去限制只播放才横屏,其他节目都是竖屏 if (self.allowRotation) { return UIInterfaceOrientationMaskAll; } return UIInterfaceOrientationMaskPortrait;}
2,KxMovieViewController 类添加进入全屏和退出全屏的函数,在初始化和返回的事件中调用
- (void)begainFullScreen {//进入全屏 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.allowRotation = YES;}- (void)endFullScreen {//退出全屏 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.allowRotation = NO; //强制归正: if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { SEL selector = NSSelectorFromString(@"setOrientation:"); NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:[UIDevice currentDevice]]; int val =UIInterfaceOrientationPortrait; [invocation setArgument:&val atIndex:2]; [invocation invoke]; }}
在初始化事件中调用
- (id) initWithContentPath: (NSString *) path parameters: (NSDictionary *) parameters { NSAssert(path.length > 0, @"empty path"); [self begainFullScreen];//进入全屏 ....}
在返回事件中调用
- (void) doneDidTouch: (id) sender{ if (self.presentingViewController || !self.navigationController) [self dismissViewControllerAnimated:YES completion:nil]; else [self.navigationController popViewControllerAnimated:YES]; [self endFullScreen]; //退出全屏,而且将屏幕强制为竖屏,这句只能放在返回之后,之前会导致crash,因为旋屏设置 冲突}
结果大致可以接受,但不够理想,因为kxmovie返回后可以看到原界面从横屏转为竖屏的动画,姑且这样吧。如果看官有好的方法,还请不吝赐教!!!
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- CDN缓存那些事
- java发送邮件
- 物联网发展的最大驱动力是嵌入式
- Android 解决ViewPager+Fragment懒加载的问题
- Android日期时间控件的学习笔记
- 文章标题
- 复杂背景彩色人脸检测
- PowerDesigner提示This data item is already used in a primary identifier.的处理
- Ubuntu免sudo使用Docker
- 微信端开发 如何给未加载的元素添加click事件
- Result Maps collection does not contain value for frontpreviewprofitManage.cdata
- LeetCode 217. Contains Duplicate
- Android上从相册选择后剪裁图片
- Android自定义View绘制彩色圆弧