iOS 屏幕旋转 状态栏 隐藏问题

一、首先说一下关于在做视频播放过程中,全屏时屏幕旋转的问题

如果程序的所有VC都不需要屏幕旋转,有两种解决方案:第一是在info.plist文件中,将Supported interface orientations  属性下的Landscape(left home button)和 Landscape(right home button) item删除,只留下Portrait item,程序就不会发生屏幕旋转。

第二种:在Appdelegate.m中重写

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

始终返回 UIInterfaceOrientationMaskLandscapeLeft

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

return UIInterfaceOrientationMaskLandscapeLeft;

}

如果需要在部分VC中使用全屏,部分VC中使用竖屏。

以下是我个理解,可能不太准确,还希望更多的大牛指正

我发现,每当设备旋转或者程序强制旋转时,系统就会调用 Appdelegate 对象的-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window方法。根据其返回值确定屏幕的方向。

因此思路就是:在Appdelegate类中增加一个UIInterfaceOrientationMask
属性,然后重写-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 方法,

iOS 屏幕旋转 状态栏 隐藏问题_第1张图片

当某一个VC需要屏幕旋转时,将UIinterfaceOriensMask设置为指定的值,然后在当前的VC中执行如下代码

- (void)interfaceOrientation:(UIInterfaceOrientation)orientation{

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= orientation;

[invocation setArgument:&val atIndex:2];

[invocation invoke];

}

iOS 屏幕旋转 状态栏 隐藏问题_第2张图片

系统就会调用-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 方法,修改当前屏幕方向。

<今天太晚了,明天要上班呢,明天晚上更新statusBar的问题,后续我一把我写的demo和视频的的一个小框架传上来,供大家参考斧正>

你可能感兴趣的:(iOS 屏幕旋转 状态栏 隐藏问题)