我有一個UIViewController,我將其作爲子視圖添加到我的iPad應用程序中。 UIViewcontroller有一個UITableView,它根據故事板中設置的自動佈局調整大小。我想顯示從iPad的中央到右端(橫向模式)移動此視圖的動畫。爲此,我將寬度初始設置爲0並將其增加到動畫塊中。儘管動畫效果很好,但UIViewController中的tableview在動畫之前添加。所以它不動畫。 IT也應該擴展其父(UIViewController)。我的代碼:添加帶AutoLayout內容的UIViewController時,內容動畫無法正常工作
@IBAction func tappedNotifications(_ sender: UIButton) {
let storyboard = UIStoryboard(name: "Content_iPad", bundle: nil)
let notificationSettingsVC = storyboard.instantiateViewController(withIdentifier:"SettingsViewController_iPad")
notificationSettingsVC.view.frame = CGRect(x: 380, y: 0, width: 0, height: 775)
self.view.addSubview(notificationSettingsVC.view)
notificationSettingsVC.didMove(toParentViewController: self)
UIView.animate(withDuration: 0.7, animations: {
notificationSettingsVC.view.frame = CGRect(x: 380, y: 0, width: 0, height: 775)
notificationSettingsVC.view.frame = CGRect(x: 380, y: 0, width: 570, height: 775)
notificationSettingsVC.view.setNeedsLayout()
}, completion: {
(completed) -> Void in
})
}
在viewwillappear()方法上對notificationSettingsVC控制器執行動畫工作正常 –