ios – 在swift中延迟运行动画

ios – 在swift中延迟运行动画,第1张

概述我有一个脉冲动画,我想运行3或4秒,我正在寻找一种方法来延迟和运行该动画一段时间,然后切换到下一个屏幕.我使用下面的代码来表示延迟,但是当我调用该函数时它不起作用. NSTimer.scheduledTimerWithTimeInterval(NSTimeInterval(3), target: self, selector: "functionHere", userInfo: nil, repe 我有一个脉冲动画,我想运行3或4秒,我正在寻找一种方法来延迟和运行该动画一段时间,然后切换到下一个屏幕.我使用下面的代码来表示延迟,但是当我调用该函数时它不起作用.

NSTimer.scheduledTimerWithTimeInterval(NSTimeInterval(3),target: self,selector: "functionHere",userInfo: nil,repeats: false)

如果您有任何想法,请告诉我.

let pulseAnimation = CABasicAnimation(keyPath: "opacity")    pulseAnimation.duration = 1    pulseAnimation.fromValue = 0    pulseAnimation.tovalue = 1    pulseAnimation.timingFunction = camediatimingFunction(name: kcamediatimingFunctionEaseInEaSEOut)    pulseAnimation.autoreverses = true    pulseAnimation.repeatCount = FLT_MAX    XBoxOneL.layer.addAnimation(pulseAnimation,forKey: "animateOpacity")    XBoxOneR.layer.addAnimation(pulseAnimation,forKey: "animateOpacity")
解决方法 利用UIVIEw.animate(withDuration :)的完成处理程序.基本样本如下:

func performMyAnimation() {  UIVIEw.animate(withDuration: {$duration},animations: { /* Animation Here */ },completion: { _ in self.performSegue(withIDentifIEr: "segueIDentifIErHere",sender: nil) }}

您的动画在动画块中运行.完成后,您将执行segue到下一个屏幕.

编辑:由于问题现在包括动画代码,使用CABasicAnimation,然后可能this answer for CAAnimation回调可能适合您.

基本上,您需要使用CATransaction包装CABasicAnimation调用.

CATransaction.begin()CATransaction.setCompletionBlock({    self.performSegue(withIDentifIEr: "segueIDentifIErHere",sender: nil)})// Your animation hereCATransaction.commit()
总结

以上是内存溢出为你收集整理的ios – 在swift中延迟运行动画全部内容,希望文章能够帮你解决ios – 在swift中延迟运行动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1007636.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存