我正在尝试使用Transition从左侧呈现一个新的视图控制器。这是守则。
@IBAction func presentNewVC(_ sender: Any) {
let storyBoard = UIStoryboard(name: "Main", bundle: Bundle.main)
let leftMenuController:NewViewController = storyBoard.instantiateViewController(withIdentifier: "NewViewController") as! NewViewController
leftMenuController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
leftMenuController.providesPresentationContextTransitionStyle = true
leftMenuController.definesPresentationContext = false
let transition = CATransition()
transition.duration = 1.0
transition.type = kCATransitionMoveIn
transition.subtype = kCATransitionFromLeft
transition.fillMode = kCAFillModeRemoved
view.window!.layer.add(transition, forKey: kCATransition)
present(leftMenuController, animated: false, completion: nil)
}
现在正在滑动动画时,在转换过程中现有视图在背景中也似乎在滑动。
理想情况下,透明的新视图控制器应该从左向右移动,但它也会在移动时将现有视图显示为背景。
编辑:只是为了更清晰: 它不是如何从左到右导航我正在寻找。实现了过渡和工作正常。问题不同。由于我的左侧菜单视图是透明的,因此从左到右呈现它时,它还显示底层现有视图,因为它在转换时具有自己的背景。 请参考屏幕截图&视频。只是想在过渡时停止这一点。只显示左侧透明视图应从左向右移动。 请参阅Video&屏幕截图了解更多细节
Click here to watch video to understand the issue
任何帮助表示感谢。
答案 0 :(得分:1)
这是我一直用于从左到右过渡的东西,这是你在找什么?
class SegueFromLeft: UIStoryboardSegue {
override func perform()
{
let src = self.source
let dst = self.destination
src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
dst.view.transform = CGAffineTransform(translationX: -src.view.frame.size.width, y: 0)
UIView.animate(withDuration: 0.25,
delay: 0.0,
options: UIViewAnimationOptions.curveEaseInOut,
animations: {
dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
},
completion: { finished in
src.present(dst, animated: false, completion: nil)
}
)
}
}