UIScrollView prevents touchesBegan, touchesMoved, touchesEnded on view controller

前端 未结 5 1902
一整个雨季
一整个雨季 2020-12-05 07:19

I am handling touches for a couple of my UI components in my view controller (custom subclass of UIViewController). It has methods touchesBegan:withEvent:,

5条回答
  •  自闭症患者
    2020-12-05 07:47

    create a subclass of UIScrollView class and override the touchesBegan: and other touch methods as follows:

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    // If not dragging, send event to next responder
      if (!self.dragging){ 
        [self.nextResponder touchesBegan: touches withEvent:event]; 
      }
      else{
        [super touchesBegan: touches withEvent: event];
      }
    }
    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    
    // If not dragging, send event to next responder
        if (!self.dragging){ 
         [self.nextResponder touchesMoved: touches withEvent:event]; 
       }
       else{
         [super touchesMoved: touches withEvent: event];
       }
    }
    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    
      // If not dragging, send event to next responder
       if (!self.dragging){ 
         [self.nextResponder touchesEnded: touches withEvent:event]; 
       }
       else{
         [super touchesEnded: touches withEvent: event];
       }
    }
    

提交回复
热议问题