T
T
Tkas2019-04-15 11:29:29
iOS
Tkas, 2019-04-15 11:29:29

Why is a view controller inactive after transitioning to it from another view controller through a navigation controller using custom animation transition?

There are 2 controllers (ViewController (starter) and SecondViewController (green)) and 1 navigation controller:
5cb43ed902036179850608.png
My project uses custom animation:

import UIKit

class TransitionManager: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate {
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return 0.8
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        var transform = CATransform3DIdentity
        let container = transitionContext.containerView
        guard let fromView = transitionContext.view(forKey: .from) else { return }
        guard let toView = transitionContext.view(forKey: .to) else { return }

        transform.m34 = -0.0019
        container.layer.sublayerTransform = transform
        container.insertSubview(toView, belowSubview: fromView)
        fromView.layer.anchorPoint = CGPoint(x: 0.0, y: 0.5)
        fromView.layer.position    = CGPoint(x: 0, y: UIScreen.main.bounds.midY)

        UIView.animate(withDuration: transitionDuration(using: transitionContext)) {
            fromView.layer.transform = CATransform3DMakeRotation(-.pi/2, 0, 1.0, 0)
        }
    }

    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return self
    }
}

The ViewController (the one with the door in the picture) uses a delay to launch the Segway to the next controller (green):
class ViewController: UIViewController {
    let transitionManager = TransitionManager()

    override func viewDidLoad() {
        super.viewDidLoad()

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
            self.performSegue(withIdentifier: "segue", sender: self)
        })
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        guard let navigationViewController = segue.destination as? UINavigationController else { return }

        navigationViewController.transitioningDelegate = transitionManager
    }
}

In the second controller there is a button, when pressed, a print should occur:
class SecondViewController: UIViewController, UIViewControllerTransitioningDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        print(view.isUserInteractionEnabled)
    }

    @IBAction func tapBtn(_ sender: UIButton) {
        print("btn pressed") //не срабатывает. Почему?
    }
}

The animation works correctly, but the button on the second controller does not respond to clicks. The line
print(view.isUserInteractionEnabled)
outputs true.
What is the problem? Why are the objects on the second controller not responding to user actions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
doublench21, 2019-04-15
@Tkas

Perhaps in completionyour animation you still need to tell the system that the animation is complete.
transitionContext.completeTransition(true)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question