我有一个使用CALayers有流动底部到顶部的气泡一些代码。 如果用户触摸屏幕,我有一些代码,与一个具有尖山当手指触摸下来替换当前正在运行的动画。 当动画切换它会导致在该设备上的闪烁(未在模拟器)。 在消除闪烁任何提示,将不胜感激! 谢谢。
代码层本身的内部流动起来的泡沫:
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"];
}
}