2016-05-12 11 views
0

私はこのキーボードとスクロールバーの問題にかなり苦しんでいます。私はWhat'sAppとiMessageに似たチャットルームを作ろうとしています。私はルートビューコントローラとしてUITabBarを持っています。私はUITextViewとUIButtonを含んでいる下部のツールバーを持っています。キーボードが表示されていると、画面からコンテンツビューがプッシュされています。コンテンツビュー。私は数字で遊んでみたが、まだそれが正しく動作するようにすることはできません。どんな助けでも大歓迎です。キーボードがUIScrollViewのコンテンツを画面外に押し出す

- (void)keyboardWasShown:(NSNotification *) aNotification { 
    NSDictionary *info = [aNotification userInfo]; 
    CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; 
    // the hardcoded 49 is the height of the UITabBar at the bottom below the input toolbar 
    UIEdgeInsets contentInsets = UIEdgeInsetsMake((-keyboardSize.height+49), 0.0, (keyboardSize.height-49), 0.0); 
    self.scrollView.contentInset = contentInsets; 
    self.scrollView.scrollIndicatorInsets = contentInsets; 

// If active text field is hidden by keyboard, scroll it so it's visible 
// Your app might not need or want this behavior. 
// CGRect aaRect = self.view.frame; 
// aaRect.size.height -= keyboardSize.height; 
// if (!CGRectContainsPoint(aaRect, self.activeTextView.frame.origin)) { 
//  [self.scrollView scrollRectToVisible:self.activeTextView.frame animated:NO]; 
// } 

    CGPoint scrollPoint = CGPointMake(0, self.scrollView.contentInset.bottom); 
    [self.scrollView setContentOffset:scrollPoint animated:true]; 


    [self.view addGestureRecognizer:self.tapRecognizer]; 

} 


- (void)keyboardWillBeHidden:(NSNotification *) aNotification { 
    UIEdgeInsets contentInsets = UIEdgeInsetsZero; 
    self.scrollView.contentInset = contentInsets; 
    self.scrollView.scrollIndicatorInsets = contentInsets; 

    [self.view removeGestureRecognizer:self.tapRecognizer]; 
} 

答えて

1

私は以前に同じ問題を抱えていました。私の解決策は、キーボードのフレームを聞くことです(別のキーボードが異なるフレームを持っているため)。コンテンツのオフセットよりもスクロールビューのフレームを調整する方が簡単だと思います。

関連する問題