美文网首页
iOS UIScrollView上加子视图touchMove手势

iOS UIScrollView上加子视图touchMove手势

作者: One苹果OneDay | 来源:发表于2020-01-10 11:23 被阅读0次

    项目中有一个需求,在UIScrollView上加一个签名区域,因为签名区域是用uiview的touchMove做的,会存在手势冲突的问题,现在记录一下解决办法

    1.给scrowView加一个类目重写四个触碰时间以便于控制器能够重新接收到触碰信息

    #import "UIScrollView+touch.h"

    - (void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event {

        NSLog(@"scrowView点击");

        [supertouchesBegan:toucheswithEvent:event];

    }

    -(void)touchesMoved:(NSSet*)toucheswithEvent:(UIEvent*)event {

          NSLog(@"scrowViewh滑动");

        [supertouchesMoved:toucheswithEvent:event];

    }

    - (void)touchesEnded:(NSSet*)toucheswithEvent:(UIEvent*)event {

          NSLog(@"scrowView结束点击");

        [supertouchesEnded:toucheswithEvent:event];

    }

    - (void)touchesCancelled:(NSSet*)toucheswithEvent:(UIEvent*)event {

        [super touchesCancelled:touches withEvent:event];

    }

    2.给签名的siginView也要写上super touches方法

    #import "HJSignatureView.h"

    - (void)touchesBegan:(NSSet *)toucheswithEvent:(UIEvent*)event {

        NSLog(@"点击");

        [supertouchesBegan:toucheswithEvent:event];

        UITouch*touch = [touchesanyObject];

        CGPointcurrentPoint = [touchlocationInView:self];

        [self.signaturePathmoveToPoint:currentPoint];

        self.oldPoint= currentPoint;

    }

    - (void)touchesMoved:(NSSet *)toucheswithEvent:(UIEvent*)event {

        [supertouchesMoved:toucheswithEvent:event];

        NSLog(@"书写");

        UITouch*touch = [touchesanyObject];

        CGPointcurrentPoint = [touchlocationInView:self];

        [self.signaturePath addQuadCurveToPoint:currentPoint controlPoint:self.oldPoint];

        self.oldPoint= currentPoint;

        //设置剪切图片的区域

        [selfgetImageRect:currentPoint];

        //设置签名存在

        if (!self.isHaveSignature) {

            self.isHaveSignature = YES;

        }

        [self setNeedsDisplay];

    }

    -(void)touchesEnded:(NSSet *)toucheswithEvent:(UIEvent*)event

    {

        [supertouchesEnded:toucheswithEvent:event];

    }

    3.在viewController里接受触碰消息再判断是从哪个view里传来的,从而确定scrowview要不要滚动

    -(void)touchesMoved:(NSSet *)toucheswithEvent:(UIEvent*)event

    {

         UITouch* touch = [touchesanyObject];

         UIView* view = [touchview];

         if([viewisKindOfClass:[HJSignatureViewclass]]) {

              _mainScrowView.scrollEnabled=NO;

         }else

         {

             _mainScrowView.scrollEnabled=YES;

    }

    }

    - (void)touchesBegan:(NSSet *)toucheswithEvent:(UIEvent*)event

    {

        UITouch* touch = [touchesanyObject];

        UIView* view = [touchview];

        if([viewisKindOfClass:[HJSignatureViewclass]]) {

             _mainScrowView.scrollEnabled=NO;

        }else

        {

            _mainScrowView.scrollEnabled = YES;

        }

    }

    -(void)touchesEnded:(NSSet *)toucheswithEvent:(UIEvent*)event

    {

         UITouch* touch = [touchesanyObject];

         UIView* view = [touchview];

         if([viewisKindOfClass:[HJSignatureViewclass]]) {

              _mainScrowView.scrollEnabled=NO;

         }else

         {

             _mainScrowView.scrollEnabled=YES;

         }

    }

    相关文章

      网友评论

          本文标题:iOS UIScrollView上加子视图touchMove手势

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