有没有大佬适配了,本人不是很懂oc代码,看网上都是要操作viewcontroller的版本,也不会自己改。有大佬适配了ios16的。。或者有偿
这两天刚好遇到这个问题, 目前也不是很清楚这么获取 viewcontroller 会不会有bug, 如果后续有同学使用该方法遇到bug了, 可以回复讨论一下。
UIInterfaceOrientationMask m = isVertical ? UIInterfaceOrientationMaskPortrait : UIInterfaceOrientationMaskLandscape;
if (@available(iOS 16.0, *)) {
UIViewController *view = [[[UIApplication sharedApplication] windows] firstObject].rootViewController;
[view setNeedsUpdateOfSupportedInterfaceOrientations];
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
UIWindowScene *scene = [array firstObject];
// 屏幕方向
UIWindowSceneGeometryPreferencesIOS *geometryPreferencesIOS = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:m];
// 开始切换
[scene requestGeometryUpdateWithPreferences:geometryPreferencesIOS errorHandler:^(NSError * _Nonnull error) {
NSLog(@"错误111:%@", error);
}];
return;
}