2017-10-12 89 views
0

我在用户按下徽标后正在运行动画。 这是动画:Swift:查看MessageController后iOS动画停止(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) { 

} 

但没有奏效。

回答

0

我发现这个问题,只需重新运行在完成相同的动画,(你可以使用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") 
    } 

} 
+0

我试过了,看到动画刚刚重新启动,当我添加这个实现。如果动画处于中间位置,它将重新启动,产生波涛汹涌的效果。有没有办法解决? – ArielSD

-1

使用这个CABasicAnimation(的keyPath: “transform.rotation”)

+0

一个更详细的答案将不胜感激。 – mahdi

+0

无论如何它没有工作 – mahdi

+0

更多的上下文将是非常有用的 - 我有类似的问题。谢谢! – ArielSD