私は、複数のアニメーションを持つアプリがあり、シンプルで、オフスクリーンからオンスクリーンに移動してからオフスクリーンに戻るイメージだけです。私はアニメーションブロックを使用しています。コードは次のようになります。objective-c、アニメーションブロックのランダム化
void (^animationOne) (void) = ^{imageOne.center = d;};
void (^afterOne) (BOOL) = ^(BOOL f) {imageOne.center = dOrig;};
[UIView animateWithDuration:.85 delay:3 options:opts animations:animationOne completion:afterOne];
多かれ少なかれ同じフォーマットに従ういくつかのものがあります。しかし、私は彼らがランダムであるように見える順序をしたいと思います。問題の一部は、アニメーションとコンプリートブロックの両方が互いに固有であり、必要なので、アニメーションを配列に貼り付け、シャッフルしてから、アニメーションに使用することはできません。アニメーションブロックを使用してこれをランダム化する方法はありますか?そうでない場合、これを実行して順序をランダム化できる別の方法がありますか?ありがとう。
編集:vikingosegundoからいくつかの有用な提案のおかげで、私はこのように見えるように自分のコードを変更しました:
NSArray *animationsCompletions = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:anim1,@"animation",after1, @"completion", nil],
[NSDictionary dictionaryWithObjectsAndKeys:anim2,@"animation",after2, @"completion", nil],
[NSDictionary dictionaryWithObjectsAndKeys:anim3,@"animation",after3, @"completion", nil],
[NSDictionary dictionaryWithObjectsAndKeys:anim4,@"animation",after4, @"completion", nil],
nil];
NSDictionary *animationCompletionPair = [animationsCompletions randomElement];
[UIView animateWithDuration:.85 delay:3 options:opts animations:[animationCompletionPair objectForKey:@"animation"] completion:[animationCompletionPair objectForKey:@"completion"]];
[UIView animateWithDuration:.85 delay:8 options:opts animations:[animationCompletionPair objectForKey:@"animation"] completion:[animationCompletionPair objectForKey:@"completion"]];
[UIView animateWithDuration:.85 delay:13 options:opts animations:[animationCompletionPair objectForKey:@"animation"] completion:[animationCompletionPair objectForKey:@"completion"]];
[UIView animateWithDuration:.85 delay:18 options:opts animations:[animationCompletionPair objectForKey:@"animation"]completion:[animationCompletionPair objectForKey:@"completion"]];
しかし、今、私はプログラムを受けていますが、信号を受信:EXC_BAD_ACCESSエラー時に表示してアニメーションはロードしようとしますが、他の情報はコンパイラによって与えられません。任意の提案をいただければ幸いです。
大丈夫です、私はこれを試して、動作しているかどうかを報告します。ありがとう! :) – lunadiviner
は私を信頼しています:) – vikingosegundo
もちろん、このコードでアニメーションと補完を接続するには、1つのアニメーションと1つの補完を1つのコレクションで収集し、これを配列に配置する必要があります。 – vikingosegundo