Failure of the first responder to Touch ScrollView

How to hide keyboard on ScrollView touch event ...

The script is like this ...

-> View β†’ ScrollView β†’ Text Box

I want to hide the keyboard by touching scrollView. I tried to override the class for scrollview, but still I can not do this.

+6
objective-c iphone ios-simulator
source share
5 answers

Doing this will help:

@interface MyClass <UIScrollViewDelegate> { } @implementation - (void)viewDidLoad { yourScrollView.delegate = self; } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [myTextField resignFirstResponder]; } 

If you really want to handle the touch event, you need to subclass UIScrollView and override the method:

 - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view { } 

Learn more about UIScrollView touch

+8
source share

This is what worked for me

in your viewController viewDidLoad method

  UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapped)]; tapScroll.cancelsTouchesInView = NO; [viewScroller addGestureRecognizer:tapScroll]; 

where viewScroller is your scroller. In the tapping method we have

  - (void) tapped { [self.view endEditing:YES]; } 

I don’t know why, but the above did not help me ... although it should

+6
source share

Try the following:

Add gesturerecognizer for scrollview,

 UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)]; tapScroll.cancelsTouchesInView = NO; [yourScrollview addGestureRecognizer:tapScroll]; [tapScroll release]; 

Reset the keyboard to (tapped :) method.

+4
source share

Please take a look at this answer. This is the easiest one.

UitextField resignFirstResponder not working in scroll mode

0
source share
 - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view { [self.view endEditing:YES]; return YES; } 
0
source share

All Articles