我有一個放置在UIScrollView中的UIImageView,基本上這個UIImageView包含非常大的地圖,並在預定義的路徑上用「箭頭」指向的導航方向創建了動畫。當發生uiscrollview事件時,NSTimer沒有被觸發
但是,每當uiscrollevents發生,我認爲MainLoop凍結和NSTimer未被解僱,並停止動畫。
在UIScrollView,CAKeyFrameAnimation或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"];
}
[UIScrollView在滾動時暫停NSTimer]的可能重複(http://stackoverflow.com/questions/7059366/uiscrollview-pauses-nstimer-while-shrolling) – 2012-02-01 04:24:57