gpt4 book ai didi

ios - 推送 View Controller 时动画不会发生

转载 作者:行者123 更新时间:2023-11-30 11:04:50 28 4
gpt4 key购买 nike

我正在尝试为按钮编辑设置动画:“同时”按下 View Controller 。但是,该按钮没有动画,但 View 已正确推送。

这是我的代码:

        createAccountButton.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .allowUserInteraction, animations: {
self.createAccountButton.transform = .identity
let signUpVC = SignUpViewController()
// presentDetail(signUpVC)
let transition = CATransition()
transition.duration = 0.5
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.easeInEaseOut)
self.view.window!.layer.add(transition, forKey: kCATransition)
self.present(signUpVC, animated: false, completion: nil)
})

谢谢

最佳答案

您应该在动画 block 中为按钮设置动画,并在动画结束后执行的完成 block 中呈现下一个屏幕。

createAccountButton.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 1, options: .allowUserInteraction, animations: {
self.createAccountButton.transform = .identity
}) { _ in
let signUpVC = SignUpViewController()
// presentDetail(signUpVC)
let transition = CATransition()
transition.duration = 0.5
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.easeInEaseOut)
self.view.window!.layer.add(transition, forKey: kCATransition)
self.present(signUpVC, animated: false, completion: nil)
}

关于ios - 推送 View Controller 时动画不会发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52837610/

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