UIView隐式动画默认关闭用户交互,苹果提供一个options选项 UIViewAnimationOptionAllowUserInteraction 允许在动画期间用户交互
[UIView animateWithDuration:5 delay:0 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction animations:^{
CGRect rect = yourView.frame;
rect.origin = changeOrigin;
yourView.frame = rect;
} completion:nil];
然后重写View的- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event方法即可实现用户触摸交互
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
UIView *view = [super hitTest:point withEvent:event];
if (!view && !self.isHidden && self.alpha > 0.01) {
//presentationLayer 是动画渲染过程的图层
CALayer *presentationLayer = self.layer.presentationLayer;
CGPoint touchPoint = [self convertPoint:point toView:self.superview];
if (CGRectContainsPoint(presentationLayer.frame, touchPoint)) {
view = self;
}
}
return view;
}
网友评论