Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 23, 2012, 01: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, 01: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.
Ides is offline   0 Reply With Quote
Old Sep 30, 2012, 03: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

Similar Threads
thread Thread Starter Forum Replies Last Post
NSTextField focus don't work if is added programmatically Ivang Mac Programming 5 Oct 1, 2013 10:27 AM
Got my mini. Some things I noticed (added SSD, OWC kit, added RAM) jshbckr Mac mini 6 Oct 31, 2012 11:34 AM
Resolved: Problem with UITapGestureRecognizer isthisonetaken iPhone/iPad Programming 1 Jul 4, 2012 09:56 AM
SOLVED - Extension added to disk name, now backups don't work. HELP! iphoneuserinyyz Mac OS X 10.7 Lion 1 Jun 16, 2012 09:39 AM

Forum Jump

All times are GMT -5. The time now is 11:36 PM.

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

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