Swift:iOS动画在查看MessageController(iOS的消息页面)后停止

时间:2017-10-12 06:54:34

标签: ios swift animation message

我在用户按下徽标后运行动画。 这是动画:

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) {

}

但它不起作用。

2 个答案:

答案 0 :(得分:1)

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

}

答案 1 :(得分:-1)

用于此CABasicAnimation(keyPath:“transform.rotation”)