首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >destinationViewController之上的UIStoryboardSegue sourceViewController

destinationViewController之上的UIStoryboardSegue sourceViewController
EN

Stack Overflow用户
提问于 2015-09-21 19:04:25
回答 2查看 280关注 0票数 1

我想在destinationViewController上“滑出”我的视图控制器。这是我的代码:

代码语言:javascript
复制
override func perform()
{
    let src = self.sourceViewController
    let dst = self.destinationViewController

    dst.view.superview?.insertSubview(src.view, aboveSubview: dst.view)
    src.view.transform = CGAffineTransformMakeTranslation(0, 0)

    UIView.animateWithDuration(0.25,
        delay: 0.0,
        options: UIViewAnimationOptions.CurveEaseInOut,
        animations: {
            src.view.transform = CGAffineTransformMakeTranslation(src.view.frame.size.width * -1, 0)
        },
        completion: { finished in
            src.presentViewController(dst, animated: false, completion: nil)
        }
    )
}

幻灯片看起来不错,但是在动画过程中,destinationViewController显示为黑色,当动画完成时,destinationViewController将正确显示。

如何在segue动画过程中显示它?

编辑:

解决了它:

代码语言:javascript
复制
override func perform()
{
    let src = self.sourceViewController
    let dst = self.destinationViewController

    src.view.superview?.insertSubview(dst.view, belowSubview: src.view)
    dst.view.transform = CGAffineTransformMakeTranslation(0, 0)

    UIView.animateWithDuration(0.25,
        delay: 0.0,
        options: UIViewAnimationOptions.CurveEaseInOut,
        animations: {
            src.view.transform = CGAffineTransformMakeTranslation(src.view.frame.size.width * -1, 0)
        },
        completion: { finished in
            src.presentViewController(dst, animated: false, completion: nil)
        }
    )
}
EN

回答 2

Stack Overflow用户

发布于 2015-09-21 20:06:41

试试这个:

代码语言:javascript
复制
class FirstCustomSegue: UIStoryboardSegue {

    override func perform() {
        // Assign the source and destination views to local variables.
        var firstVCView = self.sourceViewController.view as UIView!
        var secondVCView = self.destinationViewController.view as UIView!

        // Get the screen width and height.
        let screenWidth = UIScreen.mainScreen().bounds.size.width
        let screenHeight = UIScreen.mainScreen().bounds.size.height

        // Specify the initial position of the destination view.
        secondVCView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight)

        // Access the app's key window and insert the destination view above the current (source) one.
        let window = UIApplication.sharedApplication().keyWindow
        window?.insertSubview(secondVCView, aboveSubview: firstVCView)


        // Animate the transition.
        UIView.animateWithDuration(0.4, animations: { () -> Void in
            firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, -0.0)
            secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, -0.0)

            }) { (Finished) -> Void in
                self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
                    animated: false,
                    completion: nil)
        }
    }

}
票数 2
EN

Stack Overflow用户

发布于 2015-09-21 19:54:18

尝试将情节提要ID添加到您的ViewController。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32693611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档