UITextView keyboardDismissMode Bug UITextView keyboardDismissMode Bug xcode xcode

UITextView keyboardDismissMode Bug


for this issue better you code with scrollviewDelegete and simply mention when you want dismiss keyboard through ResignFirstResponder


Does seem to be a bug or just a non-ideal default state. But based on the code in the test project something like the below may work after some finer tuning.

There are two problems with the sample code, one is that you aren't doing anything about the size of the text when the keyboard does appear, so you can't use or see the text under the keyboard. There are other solutions but a quick and dirty solution is to change the frame size (in a submission app I would also grab the animation info and animate the view frame change to match the keyboard animation which is beyond the scope of this question). You do that in 'willShow' or the like, and bring it back in 'didHide' or the like.

Then, the content offset is fudged when its hidden and there does appear to be some strange states while you are dragging it offscreen before and around your callbacks for hiding and scroll view changes. I just save the state and "fix" it once the keyboard goes away and I've updated the text view.

I created a few properties and an outlet in the storyboard to fudge with the text view.

- (void) viewDidLoad{    [super viewDidLoad];    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];}- (void) keyboardWillShow:(NSNotification *)notification{    NSDictionary * info = [notification userInfo];    CGSize size = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;    CGRect rect = self.textView.frame;    rect.size.height -= size.height;    self.textView.frame = rect;}- (void)keyboardDidHide:(NSNotification *)notification{    NSLog(@"====== keyboardDidHide =======");    NSDictionary * info = [notification userInfo];    CGSize size = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;    CGRect rect = self.textView.frame;    rect.size.height += size.height;    self.textView.frame = rect;    self.hidingKeyboard = YES;}- (void) scrollViewDidScroll:(UIScrollView *)scrollView{    NSLog(@"%f", scrollView.contentOffset.y);    if(self.hidingKeyboard == YES)    {        scrollView.contentOffset = self.lastOffset;        self.hidingKeyboard = NO;        NSLog(@"====== reset =======");    }    else        self.lastOffset = scrollView.contentOffset;}