objective-c - 视图view.window返回当前keywindow吗?

【字号: 日期:2023-12-20浏览:36作者:雯心

问题描述

UIView.window属性来源于当前UIApplication.keyWindow,可以通过此属性让UIView间接获取到该视图的UIViewController类。

问题解答

回答1:

我觉得UIView.window返回的是当前view所在的那个window,未必是keywindow

回答2:

self.view.window 只是当前view的window,可能是keywindow@property(nonatomic, readonly) UIWindow *windowDescriptionThe receiver’s window object, or nil if it has none. (read-only)This property is nil if the view has not yet been added to a window.

[[UIApplication sharedApplication] keyWindow]@property(nonatomic, readonly) UIWindow *keyWindowThis property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible message.

[[UIApplication sharedApplication] windows]@property(nonatomic, readonly) NSArray *windowsThis property returns an array of the application’s visible and hidden windows. The windows are ordered back to front.回答3:

万一view是键盘上的某一块,view.window就是键盘的window。

回答4:

不一定是。

可通过view.window.keyWindow判断。

相关文章: