【问题标题】:custom Segue correct way自定义 Segue 正确方法
【发布时间】:2015-11-04 20:31:33
【问题描述】:

目前我尝试在自定义 segue 上工作,它应该如下所示:

[Destination View] 应该在 [Source View] 之后,这个 [Source View] 应该从 100% 动画到 0.1% 然后移除,在动画时间 [Destination View] 也应该在背景中.
因此,您会看到 [Source View] 在 [Destination View] 前面变小并被移除。

这是我的代码:

import UIKit

class CustomSegueFromBigtoSmall: UIStoryboardSegue {

    override func perform() {

        let sourceVC = self.sourceViewController
        let destinationVC = self.destinationViewController

        sourceVC.view.addSubview(destinationVC.view)

        UIView.animateWithDuration(0.5, delay: 0.0, options: .CurveEaseInOut, animations: { () -> Void in

            sourceVC.view.transform = CGAffineTransformMakeScale(0.1, 0.1)

            }){ (finished) -> Void in

                destinationVC.view.removeFromSuperview()

                let time = dispatch_time(DISPATCH_TIME_NOW, Int64(0.001 * Double(NSEC_PER_SEC)))

                dispatch_after(time, dispatch_get_main_queue(), { () -> Void in
                    sourceVC.presentViewController(destinationVC, animated: false, completion: nil)
                })
        }

    }

}

现在我看到了我的 [Source View],它立即变成了我的 [Destination View]。
[Destination View] 在黑色背景前变小了。一旦它“小”,它就会显示为全屏。

【问题讨论】:

    标签: ios iphone swift segue


    【解决方案1】:

    我在 iOS 9 中执行此操作的方法是使用自定义 segue 实现使其成为演示(模态)segue。然后,您的自定义 segue 只需调用 super.perform() 进行实际演示。但首先,segue 将自己设置为目标的transitionDelegate,并将其呈现样式设置为Custom。现在你只是在做一个普通的自定义过渡动画,使用你自己的过渡代理和你自己的 UIPresentationController,你可以按顺序做任何你想做的事情。

    【讨论】:

    猜你喜欢
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多