[[[[UIApplication sharedApplication]委托]窗口]和[[UIApplication sharedApplication] .keyWindow之间的差异? [英] diffrence between [[[[UIApplication sharedApplication] delegate] window] and [[UIApplication sharedApplication].keyWindow?

查看:497
本文介绍了[[[[UIApplication sharedApplication]委托]窗口]和[[UIApplication sharedApplication] .keyWindow之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我是iPhone开发的新手,任何人都可以帮助我了解以下两行之间的区别:

Hello i am newbie in iPhone development can any one help me to know difference between following two lines:

第一:

[[[[UIApplication sharedApplication] delegate] window] addSubview:UIView];

第二名:

[[UIApplication sharedApplication].keyWindow addSubview:UIView];

提前致谢。

推荐答案

它们在iOS上可能是相同的。当它们不同时,通常会呈现除应用代表主窗口之外的另一个窗口。您的应用可以拥有多个窗口,但只有 keyWindow 是在屏幕上可见并接收事件的窗口(例如,当可见和接收事件时,它可能是UIAlert,它是关键窗口)参考: https://developer.apple .com / library / content / documentation / WindowsViews / Conceptual / WindowAndScreenGuide / WindowScreenRolesinApp / WindowScreenRolesinApp.html

They could be the same on iOS. When they are different, usually you are presenting another window other than the app delegate's main window. Your app can have many windows but only the keyWindow is the window that is visible on the screen and receiving events (example could be a UIAlert when visible and receiving events it is the keywindow) reference: https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/WindowAndScreenGuide/WindowScreenRolesinApp/WindowScreenRolesinApp.html

来自文档:

- 对于 [[[UIApplication sharedApplication]委托]窗口];


演示故事板时使用的窗口。此属性包含
用于在设备的
主屏幕上显示应用程序可视内容的窗口。

The window to use when presenting a storyboard. This property contains the window used to present the app’s visual content on the device’s main screen.

ie这是您在 appDelegate.h 文件中的窗口属性

i.e this is the property window you have in your appDelegate.h file


  • [[UIApplication sharedApplication] keyWindow];

  • for [[UIApplication sharedApplication] keyWindow];

此属性保存windows数组中的UIWindow对象,该对象是
最近发送的makeKeyAndVisible消息。

This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible message.

在iOS上你在
里面的 appDelegate.m 中发送了 makeKeyAndVisible
application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

On iOS you sent makeKeyAndVisible in your appDelegate.m inside
application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

你做的创建的appDelegate窗口是keyWindow。通常银行应用程序在应用程序放在后台时切换关键窗口,以便在主页按钮被点击时保护用户敏感信息,并在应用程序处于前台时切换回主代理窗口。

此答案与:@SipkeSchoorstra,@ D-Mx和@andyDarwin合作

You made the created appDelegate window the keyWindow. Usually bank apps switch the key window when the app is put in the background to protect the users sensitive information when the home button is doubled tapped and switch back to the main delegate window when the app is in foreground.
This answer is in collaboration with: @SipkeSchoorstra, @D-Mx and @andyDarwin

这篇关于[[[[UIApplication sharedApplication]委托]窗口]和[[UIApplication sharedApplication] .keyWindow之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆