问题描述:
在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效果如下图:
查看ui结构图发现,其实他是横屏的
在iOS 13以下系统,正常显示
横屏页面返回转回竖屏方法
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
哪位同学有好的解决方案,😀 不吝赐教