2
我想提出只佔據屏幕下半部分的視圖,背景視圖保持可見並且沒有可能的交互。如何呈現一個像actionSheet一樣的UIViewController?
就像UIAlertContoller
與actionSheet
樣式。
如何在Swift中做到這一點?
我想提出只佔據屏幕下半部分的視圖,背景視圖保持可見並且沒有可能的交互。如何呈現一個像actionSheet一樣的UIViewController?
就像UIAlertContoller
與actionSheet
樣式。
如何在Swift中做到這一點?
創建視圖作爲一個正常的UIViewController,一個標識符分配給它,然後實例化它是這樣的:(把它作爲一個成員變量,雖然,你會需要它)
var controller = self.storyboard!.instantiateViewControllerWithIdentifier("yourIdentifier") as! UIViewController
,那麼你可以將其添加像
你父視圖self.addSubview(controller)
要小心,雖然它定位,你可以巧妙地製作動畫在屏幕的中間像
UIView.animateWithDuration(0.5, animations: {
controller.frame.origin.y = UIScreen.mainScreen().bounds.height/2
})
in
不過,在最初的定位應保持視圖的viewDidLayoutSubviews
方法,像
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
controller.frame.origin.y = UIScreen.mainScreen().bounds.height
}
因爲viewDidLoad
的意見真的沒有正確的框架還沒有,它會在錯誤的位置結束了
你可以實例化並將newViewController的視圖作爲子視圖添加到currentViewController中,並使用frame.origin.y =屏幕大小,然後爲上升移動動畫 –
這不是快捷方式,但可以嘗試從此調整動畫http://stackoverflow.com/ a/17792844/2535467,以便從下向上動畫,而不是從右向左。 – CaptJak