How to add a view to the top view hierarchy in Swift?

I used this:

UIApplication.sharedApplication().keyWindow?.rootViewController!.view.addSubview(self.customView)

Adding a modal view to all views in the view hierarchy in the application.

But that gives me a problem. Sometimes it adds a subview, but sometimes it doesn't work. In which case this will not work and what is the best way to add a modal view to the view hierarchy, such as UIAlertView.

+4
source share
1 answer

, , UIWindow - , , ( , ). < > . , keyWindow.

, subview , : UIApplication.sharedApplication().windows.last?.addSubview(yourSubView).

, , : UIApplication.sharedApplication().delegate?.window.

+4

All Articles