I am working iOS app. In that app i have textfields and textviews. My requirment is dismiss keyboard if user tapped space button twice even if starting of the text or ending of the text. I tried with following code
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
NSLog(@"textView.text %@",textView.text);
NSUInteger newLength = (textView.text.length - range.length) + text.length;
//for white space starting
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@" "] invertedSet];
NSString *filtered = [[text componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
if([text isEqualToString:@"\n"]) {
[sendMsgTextView resignFirstResponder];
// [self animateTextView:textView up:NO];
return NO;
}
if ([textView.text isEqualToString:filtered]) {
[sendMsgTextView resignFirstResponder];
return NO;
}
return YES;
}
But the problem is its restricting the starting of the text only. If i entered text and the tapped space multiple times, the keyboard is not dismissing or not restricting. Could any one has idea about this issue. If so, please give your valuable suggestions.