0

So I have a uiscrollview with a form of textfields. I'm trying to add an action to the background so that when the user taps on the background the keyboard retracts.

I was able to get the backgroundTap to retract the keyboard, but it disabled my uibuttons: Detecting hits in UIScrollView while still letting it do it's thing

As stated in the second answer I added this code to the viewDidLoad:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTap:)];

[scrollView addGestureRecognizer: singleTap];

Where backgroundTap is

- (IBAction)backgroundTap:(id)sender

That allowed me retract the keyboard with a backgroundTap on uiscrollview, however it disabled my cancelButton that closes the modal view of the form and also the submitButton which sends out a HTTP Post.

Any ideas why it's disabling the uibuttons?

Community
  • 1
  • 1
JGuo
  • 384
  • 2
  • 7

1 Answers1

0

Did some more searching and found the correct answer! I'll just post the link and answer here in case other people find this first.

UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];

singleTapGestureRecognizer.numberOfTapsRequired = 1;
singleTapGestureRecognizer.enabled = YES;
singleTapGestureRecognizer.cancelsTouchesInView = NO;
[tapableView addGestureRecognizer:singleTapGestureRecognizer];
[singleTapGestureRecognizer release];

Cheers, J

iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?

Community
  • 1
  • 1
JGuo
  • 384
  • 2
  • 7