4
CALLayersを使用して気泡を下から上に流すコードがあります。ユーザーが画面にタッチすると、現在実行中のアニメーションを、指が触れたtoPointを持つアニメーションに置き換えるコードがあります。アニメーションが切り替わると、デバイス上で(シミュレータ上ではなく)ちらつきが発生します。ちらつきを解消するためのヒントをいただければ幸いです!ありがとう。層自体の内部まで流れる気泡ためpositionプロパティmidのCABasicAnimationをアニメーションの途中で切り替えると、フリッカーが発生します
はコード:
CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"position"];
[animation setDelegate:self];
CGPoint position = [self position];
NSValue *prevVal = [NSValue valueWithCGPoint:position];
[animation setFromValue:prevVal];
CGPoint toPoint = CGPointMake(position.x,-100);
[animation setToValue:[NSValue valueWithCGPoint:toPoint]];
[animation setDuration:animationDuration];
[self addAnimation:animation forKey:@"flow"];
スーパー層に書き込まれたタッチポイントに近くの気泡を吸引するためのコード:
int count = [self.layer.sublayers count];
for(int i = 0; i < count ; i++) {
CALayer *layer= [self.layer.sublayers objectAtIndex:i];
CALayer *p = (CALayer*)[layer presentationLayer];
CGPoint position = [p position];
if(abs(position.x - touchPoint.x) < 100 && abs(position.y - touchPoint.y) < 100) {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
[animation setDelegate:self];
NSValue *prevVal = [NSValue valueWithCGPoint:position];
[animation setFromValue:prevVal];
[animation setToValue:[NSValue valueWithCGPoint:touchPoint]];
[animation setDuration:2.0];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseOut]];
[layer addAnimation:animation forKey:@"flow"];
}
}
あなたはどのように多くのサブレイヤを持っていますか?覚えておいて、シミュレータはほとんど常にデバイスより高速です。また、より穏やかなアニメーション遷移のためにEaseInEaseOutを試してみてください。 – amattn
この回答を確認することができます:http://stackoverflow.com/a/25611323/1953178 –