2017-05-29 68 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

相關問題