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 设置动画向下(就像悬停一样)循环
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01