overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() let square = UIVIEw() square.frame = CGRect(x: 55,y: 300,wIDth: 40,height: 40) square.backgroundcolor = UIcolor.redcolor() self.vIEw.addSubvIEw(square) let duration = 1.0 let delay = 0.0 let options = UIVIEwKeyframeAnimationoptions.Repeat UIVIEw.animateKeyframesWithDuration(duration,delay: delay,options: options,animations: { let fullRotation = CGfloat(M_PI * 2) UIVIEw.addKeyframeWithrelativeStartTime(0,relativeDuration: 1/3,animations: { square.transform = CGAffinetransformMakeRotation(1/3 * fullRotation) }) UIVIEw.addKeyframeWithrelativeStartTime(1/3,animations: { square.transform = CGAffinetransformMakeRotation(2/3 * fullRotation) }) UIVIEw.addKeyframeWithrelativeStartTime(2/3,animations: { square.transform = CGAffinetransformMakeRotation(3/3 * fullRotation) }) },completion: {finished in }) }解决方法 这真的很奇怪… UIVIEw.animateKeyframesWithDuration不能正常工作,因为我希望它与UIVIEwKeyframeAnimationoptions.CalculationModelinear | UIVIEwKeyframeAnimationopti ons.Repeat传入了选项.
如果使用非块方法创建关键帧动画(请参见下文),则旋转将按预期重复.
如果我发现为什么基于块的选项不起作用,我会尝试记住在这里更新答案!
overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() let square = UIVIEw() square.frame = CGRect(x: 55,height: 40) square.backgroundcolor = UIcolor.redcolor() self.vIEw.addSubvIEw(square) let fullRotation = CGfloat(M_PI * 2) let animation = CAKeyframeAnimation() animation.keyPath = "transform.rotation.z" animation.duration = 2 animation.removedOnCompletion = false animation.fillMode = kCAFillModeForwards animation.repeatCount = float.infinity animation.values = [fullRotation/4,fullRotation/2,fullRotation*3/4,fullRotation] square.layer.addAnimation(animation,forKey: "rotate")}总结
以上是内存溢出为你收集整理的ios – 使用animateKeyframesWithDuration在屏幕上创建一个连续旋转的方块全部内容,希望文章能够帮你解决ios – 使用animateKeyframesWithDuration在屏幕上创建一个连续旋转的方块所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)