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)...
Asked
Active
Viewed 3,725 times
4
-
1Are you looking for : http://stackoverflow.com/questions/5143873/dismissing-the-keyboard-in-a-uiscrollview ? – Bhavin May 17 '13 at 10:08
-
`[yourtxtFld resignFirstResponder];` – Buntylm May 17 '13 at 10:09
-
@sivakumar see my answer that will be solve your problem – Dharmbir Singh May 17 '13 at 10:15
8 Answers
6
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];
}

Mano
- 670
- 1
- 9
- 28
1
Try to use this one. And i hope it will be helpful.
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard:)];
gestureRecognizer.delegate = self;
[scrollView addGestureRecognizer:gestureRecognizer];
}
-(void) hideKeyBoard:(UIGestureRecognizer *) sender
{
[self.view endEditing:YES];
}

Dharmbir Singh
- 17,485
- 5
- 50
- 66
1
set the scrollview Delegate to self
self.scrollView.delegate=self;
then
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (sTitle.isFirstResponder) {
[sTitle resignFirstResponder];
}
}
-
1Or better to use: `-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView` – Resty Apr 17 '14 at 11:24
1
You can use this code to hide the keyboard:
-(void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideTheKeyBoard:)];
gestureRecognizer.delegate = self;
[scrollView addGestureRecognizer:gestureRecognizer];
}
-(void) hideTheKeyBoard:(UIGestureRecognizer *)sender
{
[self.view endEditing:YES];
}

Ajay Chaudhary
- 1,993
- 15
- 23
0
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setDelegate:self];
[scrollview addGestureRecognizer:tapRecognizer];
-(void)tapped:(id)sender {
[textField resignFirstResponder];
// your code what you want
}

SAMIR RATHOD
- 3,512
- 1
- 20
- 45
0
if you are using xib
then just connect a tapRecognizer
to your scrollview
and then create tapRecognizer's
selector event to [self.view endEditing:YES]

Vaibhav Saran
- 12,848
- 3
- 65
- 75
0
add custom button on scrollview and
-(IBAction)btn:(id)sender
{
[txt resignfirstresponder];
}
enjoy it!!

Bhavesh Nayi
- 3,626
- 1
- 27
- 42
0
UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Click)];
ScrollClick.cancelsTouchesInView = NO;
[YOUR scrollview addGestureRecognizer:ScrollClick];
- (void)Click
{
[self.view endEditing:YES];
}
Try this one. And i hope it will be helpful For You . enjoy it !

D.M Patel
- 145
- 1
- 7