Swift: iOS 动画在查看 MessageController 后停止(iOS 的消息页面)
Swift: iOS Animation stops after viewing the MessageController (message page of iOS)
我正在 运行在用户按下徽标后播放动画。
这是动画:
func rightRotateView(targetView: UIView, duration: Double = 5) {
UIView.animate(withDuration: duration, delay: 0.0, options: [.repeat, .curveLinear] , animations: {
targetView.transform = targetView.transform.rotated(by: CGFloat.pi * 5)
}) { finished in
// self.rightRotateView(targetView: targetView)
}
}
长按3秒后(此时动画应该还是运行),我为用户呈现消息控制器:
if MFMessageComposeViewController.canSendText() == true {
print(self.urgentNumber)
let recipients:[String] = ["\(self.urgentNumber as! String)"]
self.messageController.messageComposeDelegate = self as? MFMessageComposeViewControllerDelegate
self.messageController.recipients = recipients
self.messageController.body = "Hey,\nmy longitude: \(self.userLocation.coordinate.longitude) \nmy latitude: \(self.userLocation.coordinate.latitude)"
self.present(self.messageController, animated: true, completion: nil)
} else {
//handle text messaging not available
}
当我按下消息控件中的取消按钮时,我正在返回动画页面,但动画停止工作。
我试着重新运行动画之后的现在,而在
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
}
但是没有用。
用于此 CABasicAnimation(keyPath: "transform.rotation")
我发现了问题,只需在完成时重新运行相同的动画,(您可以使用 CABasicAnimation 或简单地 UIView.animate):
func rightRotateView(targetView: UIView, duration: Double = 5) {
UIView.animate(withDuration: duration, delay: 0.0, options: [.repeat, .curveLinear] , animations: {
targetView.transform = targetView.transform.rotated(by: CGFloat.pi * 5)
}) { finished in
let anim = CABasicAnimation(keyPath:"transform.rotation")
anim.fromValue = 0.000
anim.toValue = 360.0
anim.speed = 0.001
anim.repeatCount = .infinity
targetView.layer.add(anim, forKey: "transform.rotation")
}
}
我正在 运行在用户按下徽标后播放动画。 这是动画:
func rightRotateView(targetView: UIView, duration: Double = 5) {
UIView.animate(withDuration: duration, delay: 0.0, options: [.repeat, .curveLinear] , animations: {
targetView.transform = targetView.transform.rotated(by: CGFloat.pi * 5)
}) { finished in
// self.rightRotateView(targetView: targetView)
}
}
长按3秒后(此时动画应该还是运行),我为用户呈现消息控制器:
if MFMessageComposeViewController.canSendText() == true {
print(self.urgentNumber)
let recipients:[String] = ["\(self.urgentNumber as! String)"]
self.messageController.messageComposeDelegate = self as? MFMessageComposeViewControllerDelegate
self.messageController.recipients = recipients
self.messageController.body = "Hey,\nmy longitude: \(self.userLocation.coordinate.longitude) \nmy latitude: \(self.userLocation.coordinate.latitude)"
self.present(self.messageController, animated: true, completion: nil)
} else {
//handle text messaging not available
}
当我按下消息控件中的取消按钮时,我正在返回动画页面,但动画停止工作。 我试着重新运行动画之后的现在,而在
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
}
但是没有用。
用于此 CABasicAnimation(keyPath: "transform.rotation")
我发现了问题,只需在完成时重新运行相同的动画,(您可以使用 CABasicAnimation 或简单地 UIView.animate):
func rightRotateView(targetView: UIView, duration: Double = 5) {
UIView.animate(withDuration: duration, delay: 0.0, options: [.repeat, .curveLinear] , animations: {
targetView.transform = targetView.transform.rotated(by: CGFloat.pi * 5)
}) { finished in
let anim = CABasicAnimation(keyPath:"transform.rotation")
anim.fromValue = 0.000
anim.toValue = 360.0
anim.speed = 0.001
anim.repeatCount = .infinity
targetView.layer.add(anim, forKey: "transform.rotation")
}
}