swift 中的自定义右转

Custom right segue in swift

我正在尝试从两个视图控制器获得正确的转场,问题是当它进行转换时,第一个视图控制器进行转场,但它似乎在短时间内几乎与自身重叠,并且然后将新的视图控制器放在上面。我看了网上的其他帖子,似乎没有人遇到这个问题。

class UIStoryboardSegueFromRight: UIStoryboardSegue
{
    override func perform() {
        let src = self.source as UIViewController
        let dst = self.destination as UIViewController
        let transition: CATransition = CATransition()
        let timeFunc: CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
        transition.duration = 0.2
        transition.timingFunction = timeFunc
        transition.type = kCATransitionPush
        transition.subtype = kCATransitionFromRight

        src.view.window?.layer.add(transition, forKey: nil)
        src.present(dst, animated: false, completion: nil)
    }
}

我在下面的图片中包含了路线。源使用的是 UINavController,它的根控制器是 TabViewController。然后将该 TabViewController 附加到 UIViewController,它是使用图片右侧显示的自定义转换进行 segue 调用的控制器。

All_Feed ViewController which is the source

目标只是下面 link 中显示的 UIViewController。

Post Page ViewController which is the destination

我不是很熟悉这种在视图控制器之间转换的方法。您是否尝试过使用 UIViewControllerAnimatedTransitioninghttps://developer.apple.com/documentation/uikit/uiviewcontrolleranimatedtransitioning

与在 segue 中进行抽象相比,这还可以让您以更可重用的方式抽象逻辑。

由于您希望源显示目标,因此您可以将目标VC设为转换委托,以便连接 UIViewControllerAnimatedTransitioning 逻辑

由于您没有分享任何视觉效果,我不会尝试翻译您要完成的动画,但也许本教程还可以帮助您了解如何以这种方式实现过渡:https://www.objc.io/issues/5-ios7/view-controller-transitions/