gpt4 book ai didi

ios - 中途改变动画的速度?

转载 作者:行者123 更新时间:2023-11-28 20:05:04 25 4
gpt4 key购买 nike

我希望我的应用程序在按下按钮时播放动画,但我希望动画的速度在播放到一半时变慢?目前,当我按下按钮时,我的应用会播放声音/动画,但最后 50% 的帧速度太快,我希望它慢下来。

这是我的代码:

#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 帧是我希望它以更慢的速度播放的位置。任何帮助都会非常感谢!

最佳答案

使用当前代码,您有一个包含 22 项的数组。为了达到预期的效果,您可以使用一个包含 33 个项目的数组,方法是在 frame_50 之后复制每个项目,这样数组中的项目看起来像这样

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

由于文件名遵循可预测的模式,您甚至可以使用循环来创建数组。

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;

edit -- 上面的代码旨在替换数组初始化代码

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

关于ios - 中途改变动画的速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22366198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com