Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 23, 2012, 12:50 AM   #1
cthesky
macrumors member
 
Join Date: Aug 2011
UIButton in subview can't work once the UITapGestureRecognizer added in superview

Hi all,

In my application, I added UITapGestureRecognizer in a view (my app's root view). Once tap it, another new view will be added to this superview. In this new view, it consists a button. But what happened is this button cannot work properly, it cannot call its corresponding selector once I click (Touch up inside) it. Anyone know why this happened?

So, is it need to remove the UITapGestureRecognizer I added once I tap the superview and add another new view? Anyone has any suggestions?

Any comments and suggestions are welcome. Thanks a lot. :-)
cthesky is offline   0 Reply With Quote
Old Sep 23, 2012, 12:52 PM   #2
Ides
macrumors member
 
Join Date: Mar 2012
I think that UIGestureReconizers sometimes "steal" touches from buttons and other objects. At least, I've had the same problem as you have with a button not working because I added a gesture recognizer to its super view. I don't actually know a whole lot about them though, maybe you should read up.
__________________
Sudoku Solver: Step by Step Explanations
Available for FREE on the app store.
Ides is offline   0 Reply With Quote
Old Sep 30, 2012, 02:41 AM   #3
CodeBreaker
macrumors 6502
 
Join Date: Nov 2010
Location: Sea of Tranquility
Quote:
Originally Posted by cthesky View Post
Hi all,

In my application, I added UITapGestureRecognizer in a view (my app's root view). Once tap it, another new view will be added to this superview. In this new view, it consists a button. But what happened is this button cannot work properly, it cannot call its corresponding selector once I click (Touch up inside) it. Anyone know why this happened?

So, is it need to remove the UITapGestureRecognizer I added once I tap the superview and add another new view? Anyone has any suggestions?

Any comments and suggestions are welcome. Thanks a lot. :-)
The gesture recogniser will steal touches from your button. You can either disable the gesture recogniser from your view once you present your subview or you can use it's delegate methods to tell it not to receive touches on your button like this:

Code:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    CGPoint theTouchPoint = [touch locationInView:self];
    CGRect buttonRect = [mySubViewWithTheButton convertRect:myButton.frame toView:self.view];
    if (CGRectContainsPoint(buttonRect, theTouchPoint)) {
        return NO;
    }
    return YES;
}
__________________
.
CodeBreaker is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:41 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC