动画的UIImage在UIImageView的向上和向下(喜欢它的徘徊)循环 [英] Animate UIImage in UIImageView Up & Down (Like it's hovering) Loop

查看:197
本文介绍了动画的UIImage在UIImageView的向上和向下(喜欢它的徘徊)循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有我想上下移动(最多10个像素,同比下降10像素),这样出现在我的图像的图像徘徊。我怎样才能做到这一点简单的动画非常感谢!

Hello I have an image that I'd like to move up and down (Up 10 pixels and down 10 pixels) so that my image appears to be hovering. How can I do this with simple animation thanks so much!!!

推荐答案

您可以使用核心动画以动画的看法层的位置。如果配置动画是添加剂你就不必费心计算新的绝对位置,只是变化(相对位置)。

You could use Core Animation to animate the position of the views layer. If you configure the animation to be additive you won't have to bother calculating the new absolute position, just the change (relative position).

CABasicAnimation *hover = [CABasicAnimation animationWithKeyPath:@"position"];
hover.additive = YES; // fromValue and toValue will be relative instead of absolute values
hover.fromValue = [NSValue valueWithCGPoint:CGPointZero];
hover.toValue = [NSValue valueWithCGPoint:CGPointMake(0.0, -10.0)]; // y increases downwards on iOS
hover.autoreverses = YES; // Animate back to normal afterwards
hover.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"];

由于这是使用核心动画,你将需要添加QuartzCore.framework和#进口< QuartzCore / QuartzCore.h方式> 到code

这篇关于动画的UIImage在UIImageView的向上和向下(喜欢它的徘徊)循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆