問題描述:
在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
哪位同學有好的解決方案,?? 不吝賜教