UIKit学习笔记—第二节Windows

各位iOS开发大佬们好:
我是一名Swift+SwiftUI栈的iOS小白,目前还在上大三,最近准备实习,面试的过程中发现现在大公司很多还在用OC + UIKit的技术栈,OC我还在考虑要不要学,目前想先把UIKit学完,这是我在官网学习UIKit英文文档时摘录的本人认为的重点,如果你们也觉得对你们有用的话欢迎持续关注,我大概一天更一节,有事除外。格式什么的我也就不做了,翻译都是我自己翻译的,哪里不对欢迎在评论区指正,感谢各位大佬支持

今天2021年11月28日
这一章叫做Windows

Window的职责
It contains your application’s visible content.
It plays a key role in the delivery of touch events to your views and other application objects.
It works with your application’s view controllers to facilitate orientation changes.
包含该应用的所有可视化内容
分离该应用与其他应用对象
与ViewController合作响应视图变化

However, you can use your application’s window object to perform a few application-related tasks:
Use the window object to convert points and rectangles to or from the window’s local coordinate system. For example, if you are provided with a value in window coordinates, you might want to convert it to the coordinate system of a specific view before trying to use it. For information on how to convert coordinates, see Converting Coordinates in the View Hierarchy.
Use window notifications to track window-related changes. Windows generate notifications when they are shown or hidden or when they accept or resign the key status. You can use these notifications to perform actions in other parts of your application. For more information, see .

使用窗口对象将点和矩形转换与窗口的本地坐标系统相互转换。例如,如果您在窗口坐标中获得了值,您可能希望在尝试使用它之前将其转换为特定视图的坐标系统。
使用窗口通知跟踪与窗口相关的更改。Windows在显示或隐藏通知或接受或退出密钥状态时生成通知。您可以使用这些通知在应用程序的其他部分执行操作。
you create the window at launch time and should retain it and store a reference to it in your application delegate object. If your application creates additional windows, have the application create them lazily when they are needed
在启动时创建Window并且在 application委托对象中保存它的引用,如果你需要其他窗口,可以通过lazy实力化它

Windows (like all views) do not receive touch events outside of their bounds rectangle. So when creating your window in Interface Builder, it is recommended that you enable the Full Screen at Launch option in the attributes inspector.
窗口无法响应它尺寸之外的视图的点击事件,所以必须在配置时使它的尺寸为全显示屏尺寸。

因为我本人一直都是编程界面,觉得Interface Builder不舒服,所以我只看了programmatically的部分

在你的app代理类中的
application:didFinishLaunchingWithOptions:
方法中添加如下代码
self.window = UIWindow.init(frame: UIScreen.main.bounds)

When creating windows, you should always set the size of the window to the full bounds of the screen. You should not reduce the size of the window to accommodate the status bar or any other items. The status bar always floats on top of the window anyway, so the only thing you should shrink to accommodate the status bar is the view you put into your window. And if you are using view controllers, the view controller should handle the sizing of your views automatically.

创建Window计算屏幕尺寸时,你不应该将影响屏幕显示的状态栏等一系列部分剥离出去
在Window上调用addSubview添加视图对象

If the root view of your window is provided by a container view controller (such as a tab bar controller, navigation controller, or split-view controller), you do not need to set the initial size of the view yourself. The container view controller automatically sizes its view appropriately based on whether the status bar is visible

如果你的根视图是 tab bar这类容器类视图,那么你就不需要自己设置它的初始大小了,因为他会根据状态栏是否可视去自动调整自己的尺寸

Each UIWindow object has a configurable windowLevel property that determines how that window is positioned relative to other windows. For the most part, you should not need to change the level of your application’s windows.
每个UIWindow对象都有一个可以配置的windowLevel 属性,它决定和其他Window之间的位置关系

UIWindowDidBecomeVisibleNotification
UIWindowDidBecomeHiddenNotification
Window显示或隐藏时调用
UIWindowDidBecomeKeyNotification
UIWindowDidResignKeyNotification
Window转为主Window或退出主Window时调用,一个时刻只能有一个Window为主Window

在拓展屏幕上显示内容的步骤如下
At application startup, register for the screen connection and disconnection notifications.
When it is time to display content on the external display, create and configure a window.
Use the screens property of UIScreen to obtain the screen object for the external display.
Create a UIWindow object and size it appropriately for the screen (or for your content).
Assign the UIScreen object for the external display to the screen property of the window.
Adjust the resolution of the screen object as needed to support your content.
Add any appropriate views to the window.
Show the window and update it normally.

App启动阶段,预设硬件连接的断开连接时的通知
当要显示内容时,实例化并且配置一个Window
使用UIScreen的Screen属性获得拓展屏幕的对象
创建一个UIWindow对象并且使他适配你的内容或屏幕尺寸
将外部显示器的UIScreen对象分配给窗口的screen 属性。
根据需要调整屏幕对象的分辨率,以支持内容。
向窗口添加任何适当的视图。
正常的显示视图

To display a window on an external screen, you must associate it with the correct screen object. This process involves locating the proper UIScreen object and assigning it to the window’s screen property. You can get the list of screen objects from the screens class method of UIScreen. The array returned by this method always contains at least one object representing the main screen. If a second object is present, that object represents a connected external display.
要在外部屏幕上显示窗口,您必须将其与正确的屏幕对象关联。此过程涉及找到正确的UIScreen 对象并将其分配给窗口的 screen 属性。您可以从UIScreen的screens类方法中获取屏幕对象列表。此方法返回的数组始终包含至少一个代表主屏幕的对象。如果存在第二个对象,则该对象表示连接的外部显示器。
You should always associate a screen with a window before showing the window.
As soon as the window for an external screen is displayed, your application can begin updating it like any other window.

在显示窗口之前应该始终将屏幕与窗口关联起来。
一旦显示外部屏幕的窗口,就可以像任何其他窗口一样开始更新它。

Configuring the Screen Mode of an External Display
Depending on your content, you might want to change the screen mode before associating your window with it.
you might change the screen mode for screens with higher default resolutions.
The UIScreenMode class defines the attributes of a single screen mode. You can get a list of the modes supported by a screen from its availableModes property and iterate through the list for one that matches your needs.

可以根据屏幕更改屏幕显示模式,通过availableModes属性获取屏幕支持的显示模式列表

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值