0

異なるUIViewアニメーションを同時に書くことができるかどうか疑問に思います。スプライトアニメーションを同時に使用して、2つのAppleスタイルのフリップカウンターをアニメーション化しようとしています。各フリップカウンターには独自のアニメーションがあります。問題は、最初のカウンターが終了すると、2番目のフリップカウンターが実行を開始することです。

2回編集:コードは次のとおりです: https ://dl.dropbox.com/u/1348024/MultipleFlipCounters.zip

「FlipCounterView.m」と「CounterViewController」の2つの単純なクラスがあります。画面「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

あなたのコードはクラッシュしますが、クラッシュを修正した後にこれを試してみてください:

- (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 に答える
0

コードのクラッシュはアニメーション (Xcode 4.5.1) とは無関係のようです。両方のアニメーションを同時に実行したい場合は、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 に答える