ios – 在UIImageView中向上和向下动画UIImage(就像它的悬停)循环

ios – 在UIImageView中向上和向下动画UIImage(就像它的悬停)循环,第1张

概述你好,我有一个图像,我想上下移动(向上10像素,向下10像素),以便我的图像看起来像是在盘旋.我怎么能用简单的动画做到这一点非常感谢!!! 您可以使用Core Animation为视图图层的位置设置动画.如果将动画配置为加法,则不必费心计算新的绝对位置,只需更改(相对位置). CABasicAnimation *hover = [CABasicAnimation animationWithKeyP 你好,我有一个图像,我想上下移动(向上10像素,向下10像素),以便我的图像看起来像是在盘旋.我怎么能用简单的动画做到这一点非常感谢!!!解决方法 您可以使用Core Animation为视图图层的位置设置动画.如果将动画配置为加法,则不必费心计算新的绝对位置,只需更改(相对位置).
CABasicAnimation *hover = [CABasicAnimation animationWithKeyPath:@"position"];hover.additive = YES; // fromValue and tovalue will be relative instead of absolute valueshover.fromValue = [NSValue valueWithCGPoint:CGPointZero];hover.tovalue = [NSValue valueWithCGPoint:CGPointMake(0.0,-10.0)]; // y increases downwards on iOShover.autoreverses = YES; // Animate back to normal afterwardshover.duration = 0.2; // The duration for one part of the animation (0.2 up and 0.2 down)hover.repeatCount = INFINITY; // The number of times the animation should repeat[myVIEw.layer addAnimation:hover forKey:@"myHoverAnimation"];

由于这是使用Core Animation,您需要添加QuartzCore.framework和#import< QuartzCore / QuartzCore.h>进入你的代码.

总结

以上是内存溢出为你收集整理的ios – 在UIImageView中向上和向下动画UIImage(就像它的悬停)循环全部内容,希望文章能够帮你解决ios – 在UIImageView中向上和向下动画UIImage(就像它的悬停)循环所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存