iOS 13下横屏启动app

问题描述:

在xcode 11创建新的项目中,支持多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;
}
已经控制了,让他竖屏。

iOS13,横屏启动app效果如下图:


图片.png

查看ui结构图发现,其实他是横屏的


EB353DE56EE5A9E4AEF96C1B2AA7BE2A.jpg

在iOS 13以下系统,正常显示


ACA431344B8D49BD72CD0E1A7AEC78F8.jpg
横屏页面返回转回竖屏方法
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,没发现控制方向的方法

临时解决方案:
将项目不支持多window形式,删除 SceneDelegate

哪位同学有好的解决方案,😀 不吝赐教

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容