我制作了一个自定义segue,将当前 View 向左移动,并同时从右侧移动下一个 View 。当我在第一个 Segueway 上使用它时,它工作得很好,但是当在下一个 Segueway 中使用时,只有目标 View 移动。 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)
}
}
}
这是 View Controller 按钮操作方法中的代码,我在其中开始转场:
performSegueWithIdentifier("customSlideSegue", sender: self)
这是一个显示转场的视频:
谁能看出问题所在吗?或者我应该如何调试这个?感谢您的回复!
最佳答案
问题是,第二次调用 segue 时,sourceviewcontroller 的 View 变换已经具有 -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 自定义转场不适用于连续转场,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36383553/