我有一个继承 UIImageView 的可拖动类。当视图没有动画时,拖动工作正常。但是在动画时它不会响应触摸。动画完成后,触摸再次起作用。但我需要它在触摸时暂停动画并在触摸结束时恢复。我花了一整天的时间研究它,但无法弄清楚原因。
这是我的动画代码。
[UIView animateWithDuration:5.0f
delay:0
options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
animations:^{
self.center = CGPointMake(160,240);
self.transform = CGAffineTransformIdentity;
}
completion:nil
];
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
NSLog(@"touch");
CGPoint pt = [[touches anyObject] locationInView:self];
startLocation = pt;
[self.layer removeAllAnimations];
[[self superview] bringSubviewToFront:self];
}