/ /ちらつきのあるUIImageView(CoreAnimationとalpha-value)が欲しい-iphone、objective-c、core-animation

ちらつきUIImageView(CoreAnimationとアルファ値) - iphone、objective-c、core-animation

ちらつくUIImageViewが欲しいのですが。 CoreAnimationとアルファ値でそれを実現できると思います。私はこれを試しました:

for (int a = 1; a <= 100; a++) {
schwarz.alpha = 0.7;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:1];
schwarz.alpha = 0,1;
[UIView commitAnimations];
}

しかし、それは機能しません。彼はちょうど0.1に移動し、0.7には移動しません。 私もこれを試しました:

schwarz.alpha = 0.7;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:1];
schwarz.alpha = 0.1;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:1];
schwarz.alpha = 1;
[UIView commitAnimations];
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:1];
schwarz.alpha = 3;
[UIView commitAnimations];
// and so on...

そして再びそれは機能します。ちらつきを実装するにはどうすればよいですか? ありがとう!

回答:

回答№1は2

コードの問題は、[UIViewcommitAnimation]メソッドはブロックしません-つまり、コードの実装は続行され、アニメーションは非同期で実行されます。 つまり、実際には、最初にすべてのループの反復を実行してから、アニメーションが0.7から1.0まで実行されるということです...

「for」ループなしでsetAnimationDidStopSelectorを使用するだけです。

schwarz.alpha = 0.7;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:1];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
schwarz.alpha = 0.1;
[UIView commitAnimations];

キャッチ方法は次のとおりです。

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
/* Do your things here... */ }

回答№2の場合は1

1つのイベントループに追加されたすべてのUIViewアニメーションは、基本的に一緒にマージされます。 UIViewanimationDidStopSelectorを使用する必要があります。例として、以下を参照してください。

-(void)tileAnimate:(NSString*)animationID finished:(BOOL)finished context:(void*)context  {
int position = [animationID intValue];
NSString *next = [NSString stringWithFormat:@"%d", position+1];
if(position == boardSize) {
return;
}
[UIView beginAnimations:next context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:timing];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(tileAnimate:finished:context:)];
buttons[position].transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}

これを使用して、ボタンの配列を通常のサイズに縮小するアニメーションを次々に作成します。


回答№3の場合は1

もう2つのこと:

最初、 UIViewAnimationCurveEaseIn 色褪せて動作しないと思います。

次に、元のコードで次のように言います。

schwarz.alpha = 0,1;

ドットではなくコンマがあることに注意してください。興味深いことに、そのコードはコンパイルされますが、おそらく意図したとおりに動作しません。


回答№4の場合は1

これについての別の見方があります。フェードは使用していませんが、ちらつき効果は良いと思います。

http://github.com/st3fan/iphone-experiments/tree/master/Miscellaneous/Flicker/


回答№5の場合は0

投稿された最初のコードサンプルを使用しますが、 for ステートメントと行を追加します

[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:(float)number];

数字の-1は無期限に繰り返されるはずだと思いますが、100%確信はありません。