当前位置: 首页 > news >正文

iOS16.0:屏幕旋转

此文写于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 {}
http://www.lryc.cn/news/164277.html

相关文章:

  • Carla学习笔记(二)服务器跑carla,本地运行carla-ros-bridge并用rviz显示
  • 数学建模--退火算法求解最值的Python实现
  • 地理地形sdk:Tatuk GIS Developer Kernel for .NET Crack
  • Day_81-87 CNN卷积神经网络
  • 关于mybatisplus报错:Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplat的问题
  • Spring AOP基础动态代理基于JDK动态代理实现
  • 第一章 计算机系统概述 五、中断和异常、系统调用
  • 【C语言】文件操作(上)
  • 【Linux】让笔记本发挥余热,Ubuntu20.04设置WiFi热点
  • 【云平台】遥感地信云平台收录
  • 23种设计模式之---单例模式
  • 蓝桥杯官网练习题(纸牌三角形)
  • 一辆新能源汽车的诞生之旅:比亚迪常州工厂探营
  • 【算法专题突破】双指针 - 最大连续1的个数 III(11)
  • java实现备忘录模式
  • aardio语言的通用数据表维护
  • 手写RPC框架--7.封装响应
  • Linux入门教程||Linux系统目录结构
  • LeetCode 88. 合并两个有序数组
  • C语言实现扫雷小游戏
  • 【linux基础(五)】Linux中的开发工具(上)---yum和vim
  • C++学习之list的实现
  • 一种高效且节约内存的聚合数据结构的实现
  • 机器学习(10)---特征选择
  • Python之数据库(MYSQL)连接
  • 【建站教程】使用阿里云服务器怎么搭建网站?
  • 【自然语言处理】关系抽取 —— MPDD 讲解
  • 深入理解JVM虚拟机第三篇:JVM的指令集架构模型和JVM的生命周期
  • [小尾巴 UI 组件库] 组件库配置与使用
  • Linux系统中fork()函数的理解