我想從我創建一個自定義動畫,其正常工作頂部添加視圖控制器。然而,這是所添加的視圖控制器的背景顏色設置爲黑色,在那裏,因爲我只是希望它是透明的,使得下面的視圖控制器可以是可見的。斯威夫特 - 讓UIViewController中可見,同時增加動畫從TOP(通過self.present)新的ViewController
這裏是添加自定義動畫代碼:
let vc = Global.sharedInstance.storyboard.instantiateViewController(withIdentifier: "AnimationViewControllerID") as! AnimationViewController
vc.view.backgroundColor = UIColor.clear
vc.personName = name
let begin = CGRect(x: 0, y: -vc.view.frame.height, width: vc.view.frame.width, height: vc.view.frame.height)
let end = CGRect(x: 0, y: 0, width: vc.view.frame.width, height: vc.view.frame.width)
self.present(vc, animated: false) {() -> Void in
vc.view.frame = begin
vc.view.alpha = 0.5
vc.view.backgroundColor = UIColor.clear
UIView.animate(withDuration: 1, animations: {() -> Void in
vc.view.frame = end
},
completion: nil)
}
我嘗試設置視圖控制器的背景顏色來清除,但仍,它不是使背景透明。
這種技術(無動畫呈現,然後動畫演示完成後)是有限的(你不能讓它互動;外觀的方法'viewDidAppear'被稱爲在錯誤的時間,等等) 。你想要的是自定義轉換。見https://stackoverflow.com/a/42213998/1271826或https://stackoverflow.com/a/45764323/1271826自定義轉換的例子通過'present'。 – Rob
@Rob先生感謝您的信息。 –