iOS 视频横竖屏窗口解决方案

1.其他界面是竖屏,有个界面只支持横屏

#pragma mark 强制横屏的方法

- (BOOL)shouldAutorotate {

returnNO;

}

- (UIInterfaceOrientationMask) supportedInterfaceOrientations {

returnUIInterfaceOrientationMaskLandscapeRight;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

returnUIInterfaceOrientationLandscapeRight;

}

2.其他界面是竖屏,有个界面又要支持横屏又要支持竖屏

AppDelegate.h 增加 @property(nonatomic,assign)NSInteger allowRotation;//全局参数是否允许横竖屏切换

初始_allowRotaion = 0

#pragma mark 设置是否可以横竖屏切换

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

{

if(_allowRotation==1) {

returnUIInterfaceOrientationMaskAllButUpsideDown;//这个可以根据自己的需求设置旋转方向

}

else

{

return(UIInterfaceOrientationMaskPortrait);

}

}

在你需要的界面viewwillAppaear设置_allowRotaion  = 1

点击触发横屏代码

if([[UIDevicecurrentDevice]respondsToSelector:@selector(setOrientation:)]) {

SELselector =NSSelectorFromString(@"setOrientation:");

NSInvocation*invocation = [NSInvocationinvocationWithMethodSignature:[UIDeviceinstanceMethodSignatureForSelector:selector]];

[invocationsetSelector:selector];

[invocationsetTarget:[UIDevicecurrentDevice]];

intval =UIInterfaceOrientationLandscapeRight;

[invocationsetArgument:&valatIndex:2];

[invocationinvoke];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.监听屏幕旋转方向 在处理iOS横竖屏时,经常会和UIDeviceOrientation、UIInterface...
    彬至睢阳阅读 7,265评论 1 6
  • iOS 中横竖屏切换的功能,在开发iOS app中总能遇到。以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰...
    零度_不结冰阅读 6,621评论 0 0
  • 总体方向两点: model下,present方式推出界面。 push横屏,带tabbar、navigation,且...
    sfandy阅读 46,656评论 90 99
  • iOS 知识小集(横竖屏切换) 转载自 http://www.cocoachina.com/ios/2016072...
    Poison_19ce阅读 3,858评论 0 0
  • 今天是我第一天玩简书这个软件,才发现原来手机有了这么多功能了。之前都是用手机玩微信,QQ,微博,游戏,却不知道...
    禾乃木每123阅读 1,176评论 0 0