我正在尝试制作按钮编辑的动画:“同时”按下视图控制器。但是,该按钮无法设置动画,但是可以正确按下视图。
这是我的代码:
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)
})
谢谢
答案 0 :(得分:0)
您应为 animations 动画中的按钮设置动画,并在动画结束后执行的 completion 块中呈现下一个屏幕。
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)
}