2017-10-12 87 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