Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide keyboard on touch the scroll view Background? [closed]

I went through all the solutions but none are working. I am developing an app for iOS 6, ipad. I want the keyboard to go away when user touches outside (on scrollview)...

like image 505
Siva Avatar asked Jan 13 '23 09:01

Siva


1 Answers

Give the following code in viewDidLoad

-(void) ViewDidLoad
{
UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc]initWithTarget:self     action:@selector(tapped)];
tapScroll.cancelsTouchesInView = NO;
[scrollview addGestureRecognizer:tapScroll];
}

And define the function as follows

- (void) tapped
{
[self.view endEditing:YES];
}
like image 183
Mano Avatar answered Jan 28 '23 15:01

Mano