[英]IOS/Objective-C: Custom Segue Effect on Navigation Bar Compared with Show Segue
[英]iOS custom Segue - Slide over effect
我想第一次建立一個自定義segue。 所需的結果是在前一個后面創建新的ViewController,然后使之前的一個幻燈片像是從屏幕彈出/刪除一樣。 我的問題是我無法做到這一點。 如果我在前一個下面創建一個新的(在這種情況下兩個都向上滑動,一個彈出另一個插入),這是可以的,但這不是我想要做的。 我唯一能做的就是單獨滑動前一個,但它下方有一個黑色背景,而不是新視圖......
這是我的代碼(兩者都滾動到那個,這不是預期的結果):
override func perform() {
let viewControllerToRemove = self.sourceViewController.view as UIView!
let viewControllerToShow = self.destinationViewController.view as UIView!
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
viewControllerToShow.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight)
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(viewControllerToShow, aboveSubview: viewControllerToRemove)
UIView.animateWithDuration(0.6, animations: { () -> Void in
viewControllerToShow.frame = CGRectOffset(viewControllerToShow.frame, 0.0, -screenHeight)
viewControllerToRemove.frame = CGRectOffset(viewControllerToRemove.frame, 0.0, -screenHeight)
}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as UIViewController,
animated: false,
completion: nil)
}
}
歡迎任何幫助,謝謝!
您應該使用轉換管理器,請參閱以下委托:UIViewControllerAnimatedTransitioning和UIViewControllerTransitioningDelegate
對於你的動畫,如果有一個全局容器會更容易,因為在你的動畫中只有一個視圖是動畫的。
使用轉換管理器,兩個視圖都位於轉換容器中,因此您可以將destinationView作為可見背景。
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
// get reference to our fromView, toView and the container view that we should perform the transition in
let container = transitionContext.containerView()
let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!
然后設置框架以使兩個視圖在同一個地方,並執行以下操作:
container.addSubview(toView)
container.addSubview(fromView)
container.sendSubviewToBack(toView)
當您從View查看動畫時,這次您將在后台看到toView。
有關此鏈接的更多信息: http : //mathewsanders.com/animated-transitions-in-swift/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.