我想知道是否可以同时编写不同的UIView动画。 我试图同时使用精灵动画为两个Apple风格的翻转计数器制作动画。 每个翻转计数器都有自己的动画。 问题是第二个翻转计数器在第一个计数器完成时开始运行。
EDITED两次:这是代码:https://dl.dropbox.com/u/1348024/MultipleFlipCounters.zip
有两个简单的类“FlipCounterView.m”和“CounterViewController”。 点击屏幕“CounterViewController”将启动动画。 谢谢!
编辑:
添加了相关代码。
Apple风格的翻转计数器精灵动画是完成FlipCounterView类。
- (void)viewDidLoad{
[super viewDidLoad];
flipCounter1 = [[FlipCounterView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[flipCounter1 add:10];
[self.view addSubview:flipCounter1];
flipCounter2 = [[FlipCounterView alloc] initWithFrame:CGRectMake(0, 120, 200, 200)];
[flipCounter2 add:10];
[self.view addSubview:flipCounter2];
}
点击屏幕:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[UIView animateWithDuration:0.5
animations:^{
//this method made an sprite animation on flipCounter1
[flipCounter1 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
}];
[UIView animateWithDuration:0.5
animations:^{
//this method made an sprite animation on flipCounter2
[flipCounter2 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
}];
}
答案 0 :(得分:0)
您的代码崩溃,但在修复崩溃后尝试一下:
- (void)animateNow1
{
[UIView animateWithDuration:0.5
animations:^{
[flipCounter1 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
}];
}
- (void)animateNow2
{
[UIView animateWithDuration:0.5
animations:^{
[flipCounter2 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
}];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self performSelector:@selector(animateNow1) withObject:nil afterDelay:0.00];
[self performSelector:@selector(animateNow2) withObject:nil afterDelay:0.00];
}
答案 1 :(得分:0)
代码中的崩溃似乎与动画(Xcode 4.5.1)无关,如果你想同时执行两个动画,你可以在一个动画块中执行此操作(因为动画属性是相同的)。 / p>
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[UIView animateWithDuration:0.5 animations:^{
[flipCounter1 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
[flipCounter2 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
}];
}