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 6956097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:49:26+00:00 2026-05-27T14:49:26+00:00

I have a view ( parent ) with two subviews, one on top (

  • 0

I have a view (parent) with two subviews, one on top (topChild) of the other (bottomChild).

If I tap on the screen only topChild and parent receive the touch event.

What should I change to propagate the touch event to bottomChild as well?

The code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    MYView* parent = [[MYView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    parent.tag = 3;
    parent.backgroundColor = [UIColor redColor];

    MYView* bottomChild = [[MYView alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
    bottomChild.tag = 2;
    bottomChild.backgroundColor = [UIColor blueColor];
    [parent addSubview:bottomChild];

    MYView* topChild = [[MYView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
    topChild.tag = 1;
    topChild.backgroundColor = [UIColor greenColor];
    [parent addSubview:topChild];
    [self.view addSubview:parent];
}

Where MYView is a subclass of UIView that only logs touchesBegan.

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"%d", self.tag);
    [super touchesBegan:touches withEvent:event];
}

The result:

enter image description here

Touching the green area produces the following log:

TouchTest[25062:f803] 1
TouchTest[25062:f803] 3

My first idea was to make parent propagate all the touchesSomething calls to its children but (A) I suspect there might be an easier solution and (B) I don’t know which child sent the event to parent, and sending touchesSomething messages twice to the same view might cause shenanigans.

After asking the question I’ve found this post that suggests to override hitTest to change the view that receives the touches. I will try this approach and update the question if it works.

  • 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-27T14:49:27+00:00Added an answer on May 27, 2026 at 2:49 pm

    It’s an interesting problem you have that is probably something best addressed through a rethink of the way you have things structured. But to make it work the way you suggest you need to catch the touch event in the current top view, pass it to the parent and then propagate it down through all subviews of the parent view. To make this work you would need the touchesBegan: (or whatever other method you use to intercept the touch) to do nothing in all the views, doing the action only in the method called by the parent view.

    Which is really another way of saying don’t handle touches in the views, catch them but notify the parent view view and then call subview methods as required to cause the effect you want.

    - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
        // Do nothing, parent view calls my parentNotifiedTouchesBegan method
        [self.superview touchesBegan:touches withEvent:event];
    }
    
    - (void) parentNotifiedTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
        // Act on the touch here just as my sibling views are doing
    }
    

    Note I changed super to self.superview in that code. You may or may not also want to call super‘s method depending on what you are doing, and the place to call that may be in parentNotifiedTouchesBegan.

    You can know which subView sent the event of course, just use a custom method to notify the superview instead of calling its touchesBegan:. Use a self argument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created one simple list view. i have two list view, my 1st list
I have a simple parent/child type view with two columns: MYID and MYPARENTID .
I have a view with two subviews a button and an Image, I turn
I have a NavigationBar app with two views: a parent and a sub view.
I have two views (UIView) set-up: parent and child view. The child view is
I have two uiviews 1 child and 1 parent parent view has alpha .30
I have one view ,view contains two buttons and one gallery. Gallery view pleased
I have two views, the parent view opens a pop over that has a
I have a case where the child view sends notification to its parent view.
I have a UIView called activityView , which contains two subviews activityIndicator and cancelOperationsButton

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.