Animate UIImage in UIImageView Up amp; Down (Like it#39;s hovering) Loop(在 UIImageView Up amp; 中为 UIImage 设置动画向下(就像悬停一样)循环)
问题描述
您好,我有一张图像,我想上下移动(上移 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!!!
推荐答案
您可以使用 Core Animation 为视图层的位置设置动画.如果您将动画配置为 additive,您就不必费心计算新的绝对位置,只需计算变化(相对位置).
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"];
由于这是使用 Core Animation,您需要将 QuartzCore.framework 和 #import <QuartzCore/QuartzCore.h> 添加到您的代码中.
Since this is using Core Animation you will need to add QuartzCore.framework and #import <QuartzCore/QuartzCore.h> into your code.
这篇关于在 UIImageView Up & 中为 UIImage 设置动画向下(就像悬停一样)循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 UIImageView Up & 中为 UIImage 设置动画向下(就像悬停一样)循环
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
