ios动画和Android动画,在iOS中动画文本内容 – 等同于Android ValueAnimator

因为我没有找到定制的解决方案,我创建了我自己的:一个简单的动画师类,处理轻松:

// MyValueAnimation.h

typedef void (^MyAnimationBlock)(double animationValue);

@interface MyValueAnimation : NSObject

- (void)startAnimation:(MyAnimationBlock)animationBlock runtime:(NSUInteger)runtime delay:(NSUInteger)delay;

@end

// MyValueAnimation.m

#import "MyValueAnimation.h"

// Number of seconds between each animation step

#define kStepSize 0.05

@interface MyValueAnimation () {

NSTimer *timer;

NSUInteger totalRunTime; // Total duration of the animation (delay not included)

NSUInteger currentRuntime; // Time the animation is already running

MyAnimationBlock animationBlock;

}

@end

@implementation MyValueAnimation

- (void)startAnimation:(MyAnimationBlock)block runtime:(NSUInteger)runtime delay:(NSUInteger)delay {

if (timer != nil)

[timer invalidate];

timer = nil;

totalRunTime = runtime;

animationBlock = block;

currentRuntime = 0;

if (block != nil) {

if (delay > 0) {

// Wait to delay the start. Convert delay from millis to seconds

double delaySeconds = (double)delay / 1000.0;

timer = [NSTimer scheduledTimerWithTimeInterval:delaySeconds target:self selector:@selector(delayTick:) userInfo:nil repeats:false];

} else {

// Run the animation

timer = [NSTimer scheduledTimerWithTimeInterval:kStepSize target:self selector:@selector(animationTick:) userInfo:nil repeats:true];

}

}

}

- (void)delayTick:(NSTimer *)delayTimer {

// End of delay -> run animation

[delayTimer invalidate];

timer = [NSTimer scheduledTimerWithTimeInterval:kStepSize target:self selector:@selector(animationTick:) userInfo:nil repeats:true];

}

- (void)animationTick:(NSTimer *)animationTimer {

NSUInteger step = 1000 * kStepSize; // step size/length in milli seconds

currentRuntime += step;

double progress = MIN((double)currentRuntime / (double)totalRunTime,1.0);

// Progress is a value between 0 and 1. The easing function maps this

// to the animationValue which is than used inside the animationBlock

// to calculate the current value of the animiation

double animationValue = [self customEaSEOut:progress];

if (animationBlock != nil)

animationBlock(animationValue);

if (progress >= 1.0) {

// Animation complete

[timer invalidate];

timer = nil;

}

}

- (double)customEaSEOut:(double)t {

// Use any easing function you like to animate your values...

// http://rechneronline.de/function-graphs/

// http://sol.gfxile.net/interpolation/

return (1 - pow(1-t,2));

}

@end

// =============================================================

// Some code using the animation

- (void)animateValueFrom:(double)fromValue to:(double)toValue {

if (valueAnimation == nil)

valueAnimation = [[MyValueAnimation alloc] init];

MyAnimationBlock animationBlock = ^(double animationValue) {

double currentValue = fromValue + ((toValue - fromValue) * animationValue);

someLabel.text = [NSString stringWithFormat:"%dV",currentValue];

};

[valueAnimation startAnimation:animationBlock runtime:1500 delay:500];

}

也许不是最漂亮的解决方案,但它的作品:-)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
Android仿iOS桌面应用删除动画可以使用属性动画实现。以下是一个简单的实现步骤: 1. 创建一个布局文件,用于显示要删除的应用图标。在这个布局,你可以使用ImageView来显示应用图标,然后添加一个TextView来显示删除提示。 2. 在Java代码,使用属性动画设置ImageView的透明度和缩放比例。通过逐渐降低透明度和缩放比例,可以创建一个逐渐消失的效果。 3. 在动画结束时,删除应用程序,并在屏幕上显示一个Snackbar或Toast,以显示已删除的应用程序名称。 下面是一个示例代码,可以让你更好地了解如何实现这个功能: ```java public class DeleteAnimationActivity extends AppCompatActivity { private ImageView mAppIcon; private TextView mDeleteHint; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_delete_animation); mAppIcon = findViewById(R.id.iv_app_icon); mDeleteHint = findViewById(R.id.tv_delete_hint); // 设置属性动画 ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mAppIcon, "alpha", 1f, 0f); ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(mAppIcon, "scaleX", 1f, 0f); ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(mAppIcon, "scaleY", 1f, 0f); // 设置动画集合 AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(alphaAnimator, scaleXAnimator, scaleYAnimator); animatorSet.setDuration(500); // 监听动画结束事件 animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // 删除应用程序 deleteApp(); // 显示Snackbar或Toast Snackbar.make(mAppIcon, "已删除应用程序", Snackbar.LENGTH_LONG).show(); } }); // 启动动画 animatorSet.start(); } private void deleteApp() { // 删除应用程序的代码 } } ``` 在上面的代码,我们使用 ObjectAnimator 来设置透明度和缩放比例的动画,然后使用 AnimatorSet 将它们组合在一起。在动画结束时,我们删除应用程序并显示一个Snackbar或Toast。 如果你想要更加复杂的删除动画效果,可以尝试使用 PathInterpolator 或自定义 Interpolator 来控制动画的速度和加速度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值