Tôi không tin có phương pháp tích hợp để đạt được điều đó, tuy nhiên bạn có thể sử dụng Chuyển tiếp tùy chỉnh, được giới thiệu trong iOS7. Có rất nhiều hướng dẫn tuyệt vời trên mạng, tôi đã thêm một số liên kết bên dưới và một số mã mẫu thể hiện cách bạn có thể trượt trình điều khiển chế độ xem mới xuống từ trên cùng.
Trang web để kiểm tra:
(Lưu ý: cách UIViewController
's view
được truy cập trong hướng dẫn thứ ba và thứ tư là lỗi thời. Thay vì toViewController.view
bạn nên sử dụng transitionContext.viewForKey(UITransitionContextToViewKey)
)
Một ví dụ:
Thứ nhất, bạn sẽ cần phải thiết lập kịch bản của bạn, mà tôi sẽ giả sử bạn đã làm.
Thứ hai, bạn cần một lớp con NSObject
phù hợp với UIViewControllerAnimatedTransitioning
. Điều này sẽ được sử dụng để kiểm soát quá trình chuyển đổi từ một bộ điều khiển xem sang bộ điều khiển xem tiếp theo.
class TransitionManager : NSObject, UIViewControllerAnimatedTransitioning {
let animationDuration = 0.5
func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {
return animationDuration
}
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView()
let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!
containerView.addSubview(toView)
let finalFrame = containerView.bounds
let initalFrame = CGRect(x: 0, y: -finalFrame.height, width: finalFrame.width, height: finalFrame.height)
toView.frame = initalFrame
UIView.animateWithDuration(animationDuration,
animations: { toView.frame = finalFrame },
completion: { _ in transitionContext.completeTransition(true) })
}
}
Như đã trình bày trong RayWenderlich: How To Make A View Controller Transition Animation Like in the Ping App hướng dẫn, bạn sẽ cần phải thiết lập một đại biểu UINavigationController
của bạn. Lớp NavigationControllerDelegate
sau đây sẽ được sử dụng để trả về một thể hiện của TransitionManager
khi một segue đẩy đang được tiến hành:
class NavigationControllerDelegate: NSObject, UINavigationControllerDelegate {
let transitionManager = TransitionManager()
func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if operation == .Push {
return transitionManager
}
return nil
}
}
Và đó nên được nó! Để mở rộng điều này, tôi khuyên bạn nên xem Chuyển tiếp tương tác.