成都网站建设低价,wordpress媒体库只有2m,梅州建站网络有限公司,平面设计广告设计此文写于2022年08月03日#xff0c;距离iOS16正式版推出还有一个多月的时间#xff0c;iOS16 beta版本有很多API的修改#xff0c;今天讨论的是屏幕旋转#xff0c;基于Xcode 14.0 beta4。 之前的屏幕旋转会报错#xff1a; [Orientation] BUG IN CLIENT OF UIKIT: Settin…此文写于2022年08月03日距离iOS16正式版推出还有一个多月的时间iOS16 beta版本有很多API的修改今天讨论的是屏幕旋转基于Xcode 14.0 beta4。 之前的屏幕旋转会报错 [Orientation] BUG IN CLIENT OF UIKIT: Setting UIDevice.orientation is not supported. Please use UIWindowScene.requestGeometryUpdate(_:)
那我们看看 UIWindowScene.requestGeometryUpdate(_:) 怎么使用呢 - (void)requestGeometryUpdateWithPreferences:(UIWindowSceneGeometryPreferences *)geometryPreferences errorHandler:(void (^)(NSError *error))errorHandler;找到 Method 看到需要入参 UIWindowSceneGeometryPreferences * UIWindowSceneGeometryPreferences 也是新增的API很明显 UIWindowSceneGeometryPreferencesIOS 才是我们需要的。 - (instancetype)initWithInterfaceOrientations:(UIInterfaceOrientationMask)interfaceOrientations;UIWindowSceneGeometryPreferencesIOS 有个实例方法传入一个枚举UIInterfaceOrientationMask 到这就算摸清API使用的脉络了。
iOS16.0 横屏代码 if (available(iOS 16.0, *)) {[self setNeedsUpdateOfSupportedInterfaceOrientations];[self.navigationController setNeedsUpdateOfSupportedInterfaceOrientations];NSArray *array [[[UIApplication sharedApplication] connectedScenes] allObjects];UIWindowScene *scene (UIWindowScene *)array[0];UIWindowSceneGeometryPreferencesIOS *geometryPreferences [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:UIInterfaceOrientationMaskLandscape];[scene requestGeometryUpdateWithPreferences:geometryPreferenceserrorHandler:^(NSError * _Nonnull error) {NSLog(wuwuFQ%, error);}];} else {}