What is the difference between UIApplication.sharedApplication.delegate.window and UIApplication.sharedApplication.keyWindow?

前端 未结 4 1776
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 19:44

Can anyone help me understand the difference between the following two lines:

[UIApplication.sharedApplication.delegate.window addSubview:myView];

4条回答
  •  执念已碎
    2020-12-04 19:50

    The simplest setup is to just have one UIWindow. Usually that window is kept as a property on your app delegate. The keyWindow is the one that is designated to receive keyboard and other non-touch related events. Only one window at a time may be the key window. So if you add a 2nd window and make it the keyWindow (via [window makeKeyAndVisible]), your lines return different windows!

提交回复
热议问题