ios - 通过导航 Controller 使用自定义动画转换到 SecondViewController 中的非事件 View 后

标签 ios swift animation uinavigationcontroller custom-transition

我有 2 个 View Controller (ViewController 和 SecondViewController)和 1 个导航 Controller :enter image description here

我的项目使用从 ViewController 到 SecondViewController 的自定义过渡动画:

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
    }
}

在 ViewController(其中门图像)中,我使用延迟来启动过渡动画并转到 SecondViewController(其中绿色背景)。

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
    }
}

SecondViewController具有按钮按下功能:

class SecondViewController: UIViewController, UIViewControllerTransitioningDelegate {

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

    @IBAction func tapBtn(_ sender: UIButton) {
        print("btn pressed") //it is not worked. Why?
    }
}

动画工作正常,但 SecondViewController(绿色背景)不响应按钮按下。 SecondViewController 中的代码

print(view.isUserInteractionEnabled)

返回真。我的代码问题出在哪里?我想按下按钮来工作。

最佳答案

可能是编辑器出现故障 尝试: - 重新启动 Xcode - 清理项目 - 删除按钮及其引用,然后重新添加它们

关于ios - 通过导航 Controller 使用自定义动画转换到 SecondViewController 中的非事件 View 后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55683411/

相关文章:

ios - 在iOS中使用Restkit将JSON传递给请求主体

ios - 如何创建 cocoapod 库

ios - 没有模糊 View 效果的 UIAlertController 操作表

html - 如何在一定时间后(在网页上)停止 GIF 动画?

jquery - 使用 JQuery 缩放锯齿状图像

ios - AngularStrap 日期选择器不会在 IOS Safari 浏览器中触发事件模糊时消失

ios - TableViewCell 中的更改立即生效

iOS 操作扩展加载时间慢

Swift Core 数据文本字段和 uiimage 放入 tableview 单元格

javascript - 如何更改此 "snow script"中雪的颜色