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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:29:13+00:00 2026-06-01T04:29:13+00:00

I have a two UIViews filled with UIButtons. I want to only allow one

  • 0

I have a two UIViews filled with UIButtons. I want to only allow one button to accept touches at a time PER UIView. That is to say I want multitouch working if you have one finger in each group of buttons but not if you have both fingers in the same group.

Of course exclusiveTouch set on the buttons makes sure only one button at a time is touched but it does it for the entire window. Is there a way to only allow one touch per UIView instead of the entire window?

Update: So to give a better understand of the desired function. I want a user to be able to select a red and blue card using multitouch. Easy. BUT I don’t want them to be able to select two red cards or anything like that. Problem is if I turn on exclusiveTouch on the cards only one card in the WHOLE WINDOW can be selected at a time. The desired functionality is to have exclusiveTouch only operate PER UIVIEW which each set of cards is wrapped in its own UIView already.

Update 2: Just wanted to throw in that I am trying to find a solution that DOESN’T involve subclassing or otherwise overriding UIView’s touch controllers. That is a last resort.

Here is an image

  • 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-06-01T04:29:14+00:00Added an answer on June 1, 2026 at 4:29 am

    When touching down one of your buttons, you may set userInteractionEnabled property of another button to NO and set it back to YES while touching up.

    UPDATE 1

    Sorry, I was an idiot.

    UPDATE 2

    …

    UPDATE 3

    Finally I got back to XCode. This code works (if I understood your aim correctly):

    @interface ViewController : UIViewController {
        NSMutableArray *leftButtonsArray;
        NSMutableArray *rightButtonsArray;
    }
    
    @end
    

    //

    @implementation ViewController
    
    #pragma mark - Objects Processing
    
    - (void)buttonDownAct:(UIButton *)sender {
        sender.backgroundColor = [UIColor greenColor];
    
        NSArray *targetArray = nil;
        if ([leftButtonsArray indexOfObject:sender] == NSNotFound)
            targetArray = rightButtonsArray;
        else
            targetArray = leftButtonsArray;
    
        for (UIButton *button in targetArray)
            if (button != sender)
                button.userInteractionEnabled = NO;
    }
    - (void)buttonUpAct:(UIButton *)sender {
        NSArray *targetArray = nil;
        if ([leftButtonsArray indexOfObject:sender] == NSNotFound) {
            targetArray = rightButtonsArray;
            sender.backgroundColor = [UIColor blueColor];
        }
        else {
            targetArray = leftButtonsArray;
            sender.backgroundColor = [UIColor redColor];
        }
    
        for (UIButton *button in targetArray)
            button.userInteractionEnabled = YES;
    }
    
    #pragma mark - View lifecycle
    
    - (void)loadView {
        leftButtonsArray = [[NSMutableArray alloc] init];
        rightButtonsArray = [[NSMutableArray alloc] init];
    
        self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        self.view.backgroundColor = [UIColor whiteColor];
        float desiredWidth = self.view.frame.size.width / 4, desiredHeight = self.view.frame.size.height / 2;
    
        for (int i = 0; i < 4; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectInset(CGRectMake(desiredWidth * (i % 2), desiredHeight * (i / 2), desiredWidth, desiredHeight), 10, 10);
            [button setBackgroundColor:[UIColor redColor]];
            [button addTarget:self action:@selector(buttonDownAct:) forControlEvents:UIControlEventTouchDown];
            [button addTarget:self action:@selector(buttonUpAct:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
    
            [self.view addSubview:button];
            [leftButtonsArray addObject:button];
        }
    
        for (int i = 0; i < 4; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectInset(CGRectOffset(CGRectMake(desiredWidth * (i % 2), desiredHeight * (i / 2), desiredWidth, desiredHeight), self.view.frame.size.width / 2, 0), 10, 10);
            [button setBackgroundColor:[UIColor blueColor]];
            [button addTarget:self action:@selector(buttonDownAct:) forControlEvents:UIControlEventTouchDown];
            [button addTarget:self action:@selector(buttonUpAct:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
    
            [self.view addSubview:button];
            [rightButtonsArray addObject:button];
        }
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two overlapping UIViews, and I want both to respond to user touches.
I have one (1) .xib with two UIViews, one on the top 1/3, the
I need to have two UITableViews on one UIView. I can make it work
I have a UIView container that has two UIImageView s inside it, one partially
I have two views in one XIB I want to switch, but I don't
I have one strange problem.I have two UItextfields in my view and a button.When
I currently have two UIViews: one of a red background and the other blue.
I have two UIButtons (start and dismiss), contained by a UIView, contained by an
I have a UIGestureRecognizer that I want to work on two different UIViews, both
I have two UIViews, UIView1 and UIView2. UIView2 is being added as a subview

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.