gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:50:48 24 4
gpt4 key购买 nike

我有 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com