【问题标题】:UIStoryboardSegue sourceViewController above destinationViewControllerUIStoryboardSegue sourceViewController 上面destinationViewController
【发布时间】:2015-12-18 01:23:44
【问题描述】:

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

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正确显示。

如何让它在转场动画中显示?

编辑:

解决了:

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)
        }
    )
}

【问题讨论】:

    标签: ios swift storyboard segue


    【解决方案1】:

    试试这个:

    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】:

      尝试将 Storyboard ID 添加到您的 ViewController。

      【讨论】:

        猜你喜欢
        • 2015-04-18
        • 1970-01-01
        • 1970-01-01
        • 2018-10-12
        • 1970-01-01
        • 2011-12-10
        • 1970-01-01
        • 2014-11-26
        • 2015-11-19
        相关资源
        最近更新 更多