我有一个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控制器执行动画工作正常 –