【问题标题】:Swift: iOS Animation stops after viewing the MessageController (message page of iOS)Swift:查看 MessageController(iOS 的消息页面)后,iOS 动画停止
【发布时间】:2017-10-12 06:54:34
【问题描述】:

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

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

}

但它不起作用。

【问题讨论】:

    标签: ios swift animation message


    【解决方案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")
        }
    
    }
    

    【讨论】:

    • 我试过这个,看到我添加这个实现时动画刚刚重新启动。如果动画在中间,它会重新开始,给出一个断断续续的效果。有没有办法解决这个问题?
    【解决方案2】:

    用于此 CABasicAnimation(keyPath: "transform.rotation")

    【讨论】:

    • 我们将不胜感激。
    • 更多关于此的上下文将非常有帮助 - 我遇到了类似的问题。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-10
    • 2017-06-17
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多