Tôi có UIImageView được đặt trong UIScrollView, Cơ bản UIImageView này giữ bản đồ rất lớn và tạo hoạt ảnh trên đường dẫn được xác định trước với hướng mũi tên chỉ định.NSTimer không được kích hoạt khi sự kiện uiscrollview xảy ra
Nhưng, bất cứ khi nào xảy ra sự cố, tôi nghĩ MainLoop bị đóng băng và NSTimer không bị sa thải và hoạt ảnh dừng lại.
Có bất kỳ tài sản hiện có nào giải quyết vấn đề này, trên UIScrollView, CAKeyFrameAnimation hoặc NSTimer không?
//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"];
}
bản sao có thể có của [UIScrollView tạm dừng NSTimer trong khi cuộn] (http://stackoverflow.com/questions/7059366/uiscrollview-pauses-nstimer-while-scrolling) –