中途更改通过动画的速度? [英] Change the speed of an animation halfway through?

查看:117
本文介绍了中途更改通过动画的速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要当一个preSS一个按钮,但我想要的动画的速度中途放慢我的应用程序来播放动画?目前,我的应用程序播放声音/动画,当我preSS一个按钮,但帧的最后50%的速度太快,我希望它慢下来。

I want my app to play an animation when a press a button however I want the speed of the animation to slow down halfway through? Currently my app plays a sound/animation when I press a button, however the last 50% of the frames are too fast and I want it to slow down.

下面是我的code:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController {

}
- (IBAction)Button {

    AudioServicesPlaySystemSound(SoundID);

}




-(IBAction)startanimating{
    animatedimage.animationImages = [NSArray arrayWithObjects:
                                     [UIImage imageNamed:@"frames_00.png"],
                                     [UIImage imageNamed:@"frames_05.png"],
                                     [UIImage imageNamed:@"frames_10.png"],
                                     [UIImage imageNamed:@"frames_15.png"],
                                     [UIImage imageNamed:@"frames_20.png"],
                                     [UIImage imageNamed:@"frames_25.png"],
                                     [UIImage imageNamed:@"frames_30.png"],
                                     [UIImage imageNamed:@"frames_35.png"],
                                     [UIImage imageNamed:@"frames_40.png"],
                                     [UIImage imageNamed:@"frames_45.png"],
                                     [UIImage imageNamed:@"frames_50.png"],
                                     [UIImage imageNamed:@"frames_50.png"],
                                     [UIImage imageNamed:@"frames_45.png"],
                                     [UIImage imageNamed:@"frames_40.png"],
                                     [UIImage imageNamed:@"frames_35.png"],
                                     [UIImage imageNamed:@"frames_30.png"],
                                     [UIImage imageNamed:@"frames_25.png"],
                                     [UIImage imageNamed:@"frames_20.png"],
                                     [UIImage imageNamed:@"frames_15.png"],
                                     [UIImage imageNamed:@"frames_10.png"],
                                     [UIImage imageNamed:@"frames_05.png"],
                                     [UIImage imageNamed:@"frames_00.png"],nil];




    [animatedimage setAnimationRepeatCount:1];
    animatedimage.animationDuration = 0.7;
    [animatedimage startAnimating];

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    NSURL *buttonURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"AVTREV" ofType:@"mp3"]];

    AudioServicesCreateSystemSoundID((__bridge CFURLRef)buttonURL, &SoundID);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

50帧就是我希望它在慢得多的速度播放。任何帮助将是非常美妙谢谢!

Frame 50 is where I want it to play at a much slower speed. Any help would be fantastic thank you!

推荐答案

随着当前code你必须在这22个项目的数组。为了达到预期的效果,你可以在其中使用数组33项,通过复制每个项目后 frame_50 ,所以数组中的条目看起来像这样

With the current code you have an array with 22 items in it. To achieve the desired effect, you can use an array with 33 items in it, by duplicating each item after frame_50, so that the entries in the array look like this

00 05 10 ... 45 50 50 50 45 45 40 40 0​​5 ... 05 00 00

00 05 10 ... 45 50 50 50 45 45 40 40 ... 05 05 00 00

由于文件名遵循predictable模式,你甚至可以用一个循环来创建阵列。

Since the filenames follow a predictable pattern, you can even use a loop to create the array.

int i;
NSString *name;
NSMutableArray *tempArray = [NSMutableArray new];
for ( i = 0; i <= 50; i += 5 )
{
    name = [NSString stringWithFormat:@"frames_%02d.png", i];
    [tempArray addObject:[UIImage imageNamed:name]];
}
for ( i = 50; i >= 0; i -= 5 )
{
    name = [NSString stringWithFormat:@"frames_%02d.png", i];
    [tempArray addObject:[UIImage imageNamed:name]];
    [tempArray addObject:[UIImage imageNamed:name]];    // add the frame twice
}
animatedImage.animationImages = tempArray;

修改 - code以上的目的是取代数组初始化code

edit -- The code above is intended to replace the array initialization code

animatedimage.animationImages = [NSArray arrayWithObjects:
                                     [UIImage imageNamed:@"frames_00.png"],
                                     [UIImage imageNamed:@"frames_05.png"],
                                     ...

这篇关于中途更改通过动画的速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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