I have a UIImageView placed in UIScrollView, Basicly this UIImageView holds very big map, and created animation on a predefined path with "arrows" pointed navigation direction.
But, whenever uiscrollevents occurs, I think MainLoop freezes and NSTimer being not fired, and animation stopped.
Are there any existing property, which solves this problem, on UIScrollView, CAKeyFrameAnimation or NSTimer?
//viewDidLoad
self.myTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(drawLines:) userInfo:nil repeats:YES];
- (void)drawLines:(NSTimer *)timer {
CALayer *arrow = [CALayer layer];
arrow.bounds = CGRectMake(0, 0, 5, 5);
arrow.position = CGPointMake(line.x1, line.y1);
arrow.contents = (id)([UIImage imageNamed:@"arrow.png"].CGImage);
[self.contentView.layer addSublayer:arrow];
CAKeyframeAnimation* animation = [CAKeyframeAnimation animation];
animation.path = path;
animation.duration = 1.0;
animation.rotationMode = kCAAnimationRotateAuto; // object auto rotates to follow the path
animation.repeatCount = 1;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.fillMode = kCAFillModeForwards;
[arrow addAnimation:animation forKey:@"position"];
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…