我一直在使用这个:
UIApplication.sharedApplication().keyWindow?.rootViewController!.view.addSubview(self.customView)
在应用程序中,要在视图层次结构中添加一个模态视图。
但是这个操作有时候会出现问题。它有时可以正常添加子视图,但有时却无法工作。 在什么情况下这种方法不起作用,如何最好地在视图层次结构中添加模态视图,就像UIAlertView一样。
UIApplication.sharedApplication().windows.last?.addSubview(yourSubView)
。UIApplication.sharedApplication().delegate?.window
。
view.bringSubviewToFront(theSubview)
。 - Daniel Krom