-1

I am using this method but keyboard isn't hiding.

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
   [_myTextView resignFirstResponder];
}

How can I dismiss the keyboard on simply touching outside the keyboard. Would be great if the solution is for both objective c and swift. Thanks

I have a query in objective C for textView inside scrollView. Please resolve. I've searched but have found no discrete solution.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Sam
  • 521
  • 1
  • 6
  • 23

1 Answers1

0

try this

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
     [self.yourScrollviewName endEditing:YES];
}

or use like

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];

    if (![[touch view] isKindOfClass:[UITextView class]]) {
        [self.view endEditing:YES];
        [self.yourScrollviewName endEditing:YES];
    }
    [super touchesBegan:touches withEvent:event];
}

the above code not work try this

- (void)viewDidLoad
{
    [super viewDidLoad];
   UITapGestureRecognizer  *resignView = [[UITapGestureRecognizer alloc]
                initWithTarget:self action:@selector(handleSingleTapforResign:)];
    resignView.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer: resignView];
}

Dismiss what ever is currently editing:

- (void) handleSingleTapforResign:(UITapGestureRecognizer *) sender
{
    [self.view endEditing:YES];
    [self.yourScrollviewName endEditing:YES];
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143