2015-04-24 51 views
1

addsubview在功能上的appdelegate - didFinishLaunchingWithOptions實現:窗口不能迅速

var testView : UIView = UIView(frame: CGRectMake(100, 100, 100, 100)) 
testView.backgroundColor = UIColor.blueColor() 
self.window?.addSubview(testView) 
self.window?.bringSubviewToFront(testView) 
self.window?.makeKeyAndVisible() 

但不顯示testView。

+1

指該視頻https://www.youtube.com/watch?v=5ibVlOx2o7I –

回答

3

所有你需要做的就是給你的窗口框架。

,你的代碼將是:

window = UIWindow(frame: UIScreen.mainScreen().bounds) 

var testView : UIView = UIView(frame: CGRectMake(0 , 0, 100, 100)) 
testView.backgroundColor = UIColor.blueColor() 
self.window?.addSubview(testView) 
self.window?.bringSubviewToFront(testView) 
self.window?.makeKeyAndVisible() 
+0

TestView顯示OK,但屏幕的黑色,我需要帶testView在導航控制器的字體中。 (testView是頁腳底部)。 TKS! – haipt

+0

你的問題是如何顯示測試視圖。你沒有提到任何其他的東西。如果這個工作,接受答案.. :) –