Tôi có 2 chức năng sau đó thêm và loại bỏ các bộ điều khiển xem đứa trẻ được kích hoạt từ một bộ điều khiển xem container:Làm cách nào để animate bộ điều khiển chế độ xem con khi thêm vào/xóa khỏi bộ điều khiển chế độ xem bộ chứa?
@discardableResult func addChildViewController(withChildViewController childViewController: UIViewController) -> UIViewController {
// Add Child View Controller
addChildViewController(childViewController)
childViewController.beginAppearanceTransition(true, animated: true)
// Add Child View as Subview
view.addSubview(childViewController.view)
// Configure Child View
childViewController.view.frame = view.bounds
childViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// Notify Child View Controller
childViewController.didMove(toParentViewController: self)
return childViewController
}
@discardableResult func removeChildViewController(withChildViewController childViewController: UIViewController) -> UIViewController {
// Notify Child View Controller
childViewController.willMove(toParentViewController: nil)
childViewController.beginAppearanceTransition(false, animated: true)
// Remove Child View From Superview
childViewController.view.removeFromSuperview()
// Notify Child View Controller
childViewController.removeFromParentViewController()
return childViewController
}
Các chức năng trên là phần mở rộng để UIViewController, vì vậy tất cả tôi đang làm là self.addChildViewController() và self.removeChildViewController() trên bộ điều khiển xem cha.
Làm cách nào để tạo hiệu ứng an toàn cho chế độ xem đang được xóa khi đang xem và chế độ xem đang được thêm vào theo cách của nó?
Bạn có nhiều bộ điều khiển con và cố gắng chuyển đổi trong betweens Hoặc chỉ một duy nhất? –
Tôi có nhiều bộ điều khiển chế độ xem con, nhưng tại bất kỳ thời điểm nào, tôi sẽ thêm một bộ điều khiển và xóa bộ điều khiển cuối cùng. –
Bạn muốn hình động nào khi bộ điều khiển xem con thêm? –