0
votes

I am still really at the beginning of learning swift and making app. So I already apologize because my problem might be really obvious but I couldn't fix it with every research made for few days. I made a small app with few views embedded in a navigation controller. It works well when I use default segues (show or present modally). But I wanted to improve it by making and using a custom segue. I made the class and used it between views embedded in the NavigationVC. Then it doesn't work. When I press button in the view nothing happen. The problem do not seems to come from the custom segue because it works well when used between view not embedded in NVC. So it might be a more fundamental problem of using custom segue within NVC. Is that not possible ? Or maybe the code may be modified for views within navigation stack. Here the custom segue :

class CustomSegueRotation : UIStoryboardSegue {

override func perform() {
    let initialViewController = self.source.view
    let destinationViewController = self.destination.view
    let rotation = CAKeyframeAnimation (keyPath: "transform.rotation.y")
    rotation.values = [0, CGFloat.pi]
    rotation.autoreverses = false
    initialViewController?.addSubview(destinationViewController!)
    
    UIView.animate(withDuration: 0.3, delay: 0.05, options: .curveEaseInOut, animations: {
        initialViewController?.layer.add(rotation, forKey: nil)
    }, completion: nil)
}}

Thank you very much for the help.

1
You need to google "custom transition animation". - matt

1 Answers

0
votes

Have you tried supplying a custom UINavigationControllerDelegate that supplies the animation you wish to use for transitions?

https://developer.apple.com/documentation/uikit/uinavigationcontrollerdelegate/1621846-navigationcontroller

You would want to implement the protocol UIViewControllerAnimatedTransitioning https://developer.apple.com/documentation/uikit/uiviewcontrolleranimatedtransitioning to describe your animations.

Then return this implementation from the delegate method I mentioned above. Finally, set the delegate on your nav controller to an instance of the custom nav controller delegate.