最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift中makeKeyAndVisible的作用

Swift crifan 4129浏览 0评论
看到别人教程中,常常出现:
makeKeyAndVisible
比如:
Swift Tutorial 1: Starting with a Single View Application -> Hello World | Swift for IOS
但是自己试了试:
加上或不加上makeKeyAndVisible:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
 。。。
        self.window!.makeKeyAndVisible()

        return true
    }

好像没区别。

所以要去搞清楚:
swift makeKeyAndVisible
参考:

Makes the receiver the key window and visible.

Declaration

SWIFT

func makeKeyAndVisible()

Discussion

This is a convenience method to make the receiver the main window and displays it in front of other windows at the same window level or lower. You can also hide and reveal a window using the inherited hidden property of UIView.
好像就只是:
[总结]
makeKeyAndVisible的作用:
让此window作为主窗口
-》当然app一直只有一个window
-》所以此处调用或不调用makeKeyAndVisible,都不影响当前window是主窗口
注:同一时刻,只有一个主窗口

转载请注明:在路上 » [已解决]swift中makeKeyAndVisible的作用

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.536 seconds, using 22.06MB memory