Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 373301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:17:41+00:00 2026-05-12T14:17:41+00:00

I have a subclass of UIScrollView that overrides touchesBegan:withEvent: touchesMoved:withEvent: touchesEnded:withEvent: Overriding these three

  • 0

I have a subclass of UIScrollView that overrides

touchesBegan:withEvent:
touchesMoved:withEvent:
touchesEnded:withEvent:

Overriding these three seems to be a technique that is widely used (based on my observations in forums). However, as soon as I compiled this code on OS3, these methods are no longer being called. Has anyone else seen this problem? Is there a known fix that doesn’t use undocumented methods?

My first attempt at a solution was to move all the touchesBegan/Moved/Ended methods down into my content view and set

delaysContentTouches = NO;
canCancelContentTouches = NO;

This worked partially, but left me unable to pan when I have zoomed. My second attempt only set canCancelContentTouches = NO when there were two touches (thus passing the pinch gesture through to the content). This method was sketchy and didn’t work very well.

Any ideas? My requirement is that the scroll view must handle the pan touches, and I must handle the zoom touches.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:17:41+00:00Added an answer on May 12, 2026 at 2:17 pm

    My solution is not pretty. Basically there is a scroll view who contains a content view. The scroll view does not implement touchesBegan,Moved,Ended at all. The content view maintains a pointer to his parent (called “parentScrollView” in this example). The content view handles the logic and uses [parentScrollView setCanCancelContentTouches:…] to determine whether or not to let the parent view cancel a touch event (and thus perform a scroll event). The tap count logic is there because users rarely place both fingers onscreen at exactly the same time so the first touch must be ignored if it is very quickly followed by a second.

    -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
    {
        if(parentViewIsUIScrollView)
        {
            UIScrollView * parentScrollView = (UIScrollView*)self.superview;
            if([touches count] == 1)
            {
                if([[touches anyObject] tapCount] == 1)
                {   
                    if(numberOfTouches > 0)
                    {
                        [parentScrollView setCanCancelContentTouches:NO];
                        //NSLog(@"cancel NO - touchesBegan - second touch");
                        numberOfTouches = 2;
                    }
                    else
                    {
                        [parentScrollView setCanCancelContentTouches:YES];
                        //NSLog(@"cancel YES - touchesBegan - first touch");
                        numberOfTouches = 1;
                    }   
                }
                else
                {
                    numberOfTouches = 1;
                    [parentScrollView setCanCancelContentTouches:NO];
                    //NSLog(@"cancel NO - touchesBegan - doubletap");
                }
            }
            else
            {       
                [parentScrollView setCanCancelContentTouches:NO];
                //NSLog(@"cancel NO - touchesBegan");
                numberOfTouches = 2;
            }
            //NSLog(@"numberOfTouches_touchesBegan = %i",numberOfTouches);
        }
    }
    
    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {   
        if(touchesCrossed)
            return;
    
        if(parentViewIsUIScrollView)
        {
            UIScrollView * parentScrollView = (UIScrollView*)self.superview;
            NSArray * thoseTouches = [[event touchesForView:self] allObjects]; 
    
            if([thoseTouches count] != 2)
                return;
            numberOfTouches = 2;
    
    
            /* compute and perform pinch event */
    
            [self setNeedsDisplay];
            [parentScrollView setContentSize:self.frame.size];
        }
    }
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {   
        touchesCrossed = NO;
        if(parentViewIsUIScrollView)
        {
            numberOfTouches = MAX(numberOfTouches-[touches count],0);
            [(UIScrollView*)self.superview setCanCancelContentTouches:YES];
            //NSLog(@"cancel YES - touchesEnded");
            //NSLog(@"numberOfTouches_touchesEnded = %i",numberOfTouches);  
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a subclass of UIScrollView that I have set as the view of
I have a subclass of UIScrollView that I'm using for images slideshow, with infinite
I have a UIScrollView subclass that I am programmatically scrolling using UIView animations. I'd
I want to create a subclass of UITableView or UIScrollView that will have some
So I have a UIViewController subclass called MyTabBarViewController that has a UIScrollView. Inside of
I have a UIScrollView that I need to subclass and within the subclass I
HI All. I have subclass of UIScrollView. IN this class I have added some
i have an uiscrollview with a uiimageview inside. I subclass the uiscrollview but i
I have a subclass of UITableViewController. I have code that can add/remove a UISearchBar
I have a subclass of UIImageView that I need to know when is touched.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.