我进行了自定义搜索,将当前视图移至左侧,同时将右视图移至右侧。当我在第一个通道中使用它时,它可以完美工作,但是在下一个通道中使用时,只有目标视图移动。 segue的代码如下所示:

class CustomSlideSegue: UIStoryboardSegue {

    override func perform() {
        let firstVCView = self.sourceViewController.view as UIView!
        let secondVCView = self.destinationViewController.view as UIView!

        let screenWidth = UIScreen.mainScreen().bounds.size.width
        let screenHeight = UIScreen.mainScreen().bounds.size.height

        secondVCView.frame = CGRectMake(screenWidth, 0, screenWidth, screenHeight)

        let window = UIApplication.sharedApplication().keyWindow
        window?.insertSubview(secondVCView, aboveSubview: firstVCView)

        UIView.animateWithDuration(0.6, animations: { () -> Void in
             firstVCView.transform = CGAffineTransformMakeTranslation(-screenWidth, 0)
             secondVCView.transform = CGAffineTransformMakeTranslation(-screenWidth, 0)
    }) { (Finished) -> Void in
            self.sourceViewController.presentViewController(self.destinationViewController as UIViewController, animated: false, completion: nil)
        }
    }
}


这是我启动segue的视图控制器按钮操作方法中的代码:

performSegueWithIdentifier("customSlideSegue", sender: self)


这是显示segues的视频:

ios - Swift自定义segue在连续的segue上不起作用-LMLPHP

谁能看到这个问题?还是我应该如何调试呢?感谢您的答复!

最佳答案

问题在于,第二次调用segue时,sourceviewcontroller的视图的转换已经具有-screenWidth的值,因此不会被挤出屏幕。将您的代码更改为以下内容:

override func perform() {
    let firstVCView = self.sourceViewController.view as UIView!
    let secondVCView = self.destinationViewController.view as UIView!

    let screenWidth = UIScreen.mainScreen().bounds.size.width

    secondVCView.transform = CGAffineTransformMakeTranslation(screenWidth, 0)

    let window = UIApplication.sharedApplication().keyWindow
    window?.insertSubview(secondVCView, aboveSubview: firstVCView)

    UIView.animateWithDuration(0.6, animations: { () -> Void in
        firstVCView.transform = CGAffineTransformMakeTranslation(-screenWidth, 0)
        secondVCView.transform = CGAffineTransformIdentity
    }) { (Finished) -> Void in
        self.sourceViewController.presentViewController(self.destinationViewController, animated: false, completion: nil)
    }
}

关于ios - Swift自定义segue在连续的segue上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36383553/

10-14 19:55
查看更多