UIScrollview getting touch events

后端 未结 4 1916
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 20:45

How can I detect touch points in my UIScrollView? The touches delegate methods are not working.

4条回答
  •  渐次进展
    2020-11-28 21:27

    You can make your own UIScrollview subclass and then you can implement the following:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
    
    {
    
    NSLog(@"DEBUG: Touches began" );
    
    UITouch *touch = [[event allTouches] anyObject];
    
        [super touchesBegan:touches withEvent:event];
    }
    
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    
        NSLog(@"DEBUG: Touches cancelled");
    
        // Will be called if something happens - like the phone rings
    
        UITouch *touch = [[event allTouches] anyObject];
    
        [super touchesCancelled:touches withEvent:event];
    
    }
    
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    
        NSLog(@"DEBUG: Touches moved" );
    
        UITouch *touch = [[event allTouches] anyObject];
    
        [super touchesMoved:touches withEvent:event];
    
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"DEBUG: Touches ending" );
        //Get all the touches.
        NSSet *allTouches = [event allTouches];
    
        //Number of touches on the screen
        switch ([allTouches count])
        {
            case 1:
            {
                //Get the first touch.
                UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
    
                switch([touch tapCount])
                {
                    case 1://Single tap
    
                        break;
                    case 2://Double tap.
    
                        break;
                }
            }
                break;
        }
        [super touchesEnded:touches withEvent:event];
    }
    

提交回复
热议问题