0

我想知道是否可以同时编写不同的 UIView 动画。我试图同时使用精灵动画为两个 Apple 风格的翻转计数器设置动画。每个翻转计数器都有自己的动画。问题是当第一个计数器完成时,第二个翻转计数器开始运行。

两次编辑:这是代码: 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];
                     }];

}

4

2 回答 2

0

您的代码中的崩溃似乎与动画无关(Xcode 4.5.1),如果您希望两个动画同时执行,您可以在一个动画块中执行此操作(因为动画属性相同)。

- (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];
    }];
}
于 2012-10-14T21:27:21.770 回答
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];
}    
于 2012-10-14T20:38:43.763 回答