美文网首页
UIView动画过程实现交互

UIView动画过程实现交互

作者: Rambo__ | 来源:发表于2017-11-15 11:34 被阅读123次

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;
}

相关文章

网友评论

      本文标题:UIView动画过程实现交互

      本文链接:https://www.haomeiwen.com/subject/skscvxtx.html