iOS 13下橫屏啟動app

問題描述:

在xcode 11創(chuàng)建新的項目中,支持多window模式下,也就是存在 SceneDelegate.h文件。在appDelegate.m中
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    id rootViewController = [self topViewControllerWithRootViewController:window.rootViewController];
    if (rootViewController != nil)
    {
        if ([rootViewController respondsToSelector:@selector(canRotate)])
        {
            return UIInterfaceOrientationMaskAllButUpsideDown;
        }
    }
    return UIInterfaceOrientationMaskPortrait;
}
已經(jīng)控制了,讓他豎屏。

iOS13,橫屏啟動app效果如下圖:


圖片.png

查看ui結構圖發(fā)現(xiàn),其實他是橫屏的


EB353DE56EE5A9E4AEF96C1B2AA7BE2A.jpg

在iOS 13以下系統(tǒng),正常顯示


ACA431344B8D49BD72CD0E1A7AEC78F8.jpg
橫屏頁面返回轉(zhuǎn)回豎屏方法
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];
    }


和上面方法一樣  下面只是用了kvc 去設值
- (void)setNewOrientation:(BOOL)fullscreen{
    if (fullscreen) {
        NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
        [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
        NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
        [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
    }else{
        NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
        [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
        NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
        [[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
    }
}

???不知道是不是 uiwindowScence導致,查看了下api,沒發(fā)現(xiàn)控制方向的方法

臨時解決方案:
將項目不支持多window形式,刪除 SceneDelegate

哪位同學有好的解決方案,?? 不吝賜教

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容