ios16切换横竖屏代码
[vc.navigationController setNeedsUpdateOfSupportedInterfaceOrientations];
UIInterfaceOrientationMask faceOrientationMask = UIInterfaceOrientationMaskLandscapeRight;
NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
UIWindowScene *ws = (UIWindowScene *)array[0];
UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
geometryPreferences.interfaceOrientations = faceOrientationMask;
[ws requestGeometryUpdateWithPreferences:geometryPreferences
errorHandler:^(NSError * _Nonnull error) {
//业务代码
}];
注意:
1.ios16 开始 UIDeviceOrientationDidChangeNotification通知也失效了
2.上方代码Xcode14以下无法编译,可以用解决
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160000
#endif
3.同时注意手机系统版本判断
@available(iOS 16.0, *)
网友评论