2017-05-29 46 views
0

我有一个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 

    }) 
} 
+0

在viewwillappear()方法上对notificationSettingsVC控制器执行动画工作正常 –

回答

0

看起来你是在告诉您的通知视图控制器其宽度动画为0和570两个动画块内,尝试删除帧更改设置宽度为0

@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: 570, height: 775) 
     notificationSettingsVC.view.setNeedsLayout() 
    }, completion: { 
     (completed) -> Void in 

    }) 
} 
+0

它仍然不能正常工作,我相信问题是因为我使用了故事板的视图而不是通过编码创建 – pankaj

+0

您能否提供一些关于您的视图的更多信息控制器设置在故事板中,就像在ta上使用的约束一样视图控制器内部的可视视图等 – zfetters

相关问题