0

だから...キーボードがポップアップしたときにUIScrollViewを上に移動させ、それが機能します...ただし、UIScrollViewとキーボードが同期しないことを除いて...最初にキーボードがポップアップし、次にUIScrollViewがポップアップします。

ビューがスクロールアップすると同時にキーボードが表示されるように、キーボードを遅らせる方法があることは知っています。それ、どうやったら出来るの??私はviewDidLoadでこれを試しました:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

...そして私もこれを持っています:

- (void)keyboardWillShow:(NSNotification *)notification
{
    [NSTimer scheduledTimerWithTimeInterval:4000 target:self selector:@selector(keyboardWillShow:) userInfo:nil repeats:NO];
}

(4000 は膨大な数ですが、遅延があることを確認したかったのです!!)

また、スムーズなスクロールではなく、キーボードを閉じると、 UIScrollView は緩和するのではなく、単純に元の位置に戻ります...それを処理する合理的な方法はありますか?


アップデート:

わかりました...正しい道を歩むために私を助けてくれたSteven Fisherに感謝します...すべてをkeyboardWillShowに移動し、次のコードを追加しました:

[UIScrollView beginAnimations:nil context:NULL];
[UIScrollView setAnimationDelegate:self];
[UIScrollView setAnimationDuration:.32];
[UIScrollView setAnimationBeginsFromCurrentState:NO];

どういうわけか、キーボードが消えたときの「ジャンプ」問題も解決しました! ウーフー!

4

3 に答える 3

0
  - (void)viewDidLoad
  {

     [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWasShown:)
                                             name:UIKeyboardDidShowNotification
                                           object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWasShown:)
                                             name:UIKeyboardWillHideNotification
                                           object:nil];
 }

 - (void)keyboardWasShown:(NSNotification *)notification
{
  // To avoid keyboard hides the view
  CGRect frame = self.view.bounds; 
if (capitalTextField.enabled ==YES) 
{
     if ([notification name]== UIKeyboardDidShowNotification ) 
     {

        frame.origin.y += 200;
        [self.scrollView scrollRectToVisible:frame animated:YES];
     }
     else
     {
        frame.origin.y -= 200;
        [self.scrollView scrollRectToVisible:frame animated:YES]; 
     }
    }
  }
于 2013-02-28T03:50:01.767 に答える
0

以下のコードはポップアップを遅らせます

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3f];
[textField becomefirstresponder];
[UIView commitAnimations];
于 2013-02-28T07:19:13.573 に答える
0

これは、この種の状況に対して Apple のドキュメントに記載されているコードです。

// Call this method somewhere in your view controller setup code.
- (void)registerForKeyboardNotifications
{
   [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(keyboardWasShown:)
        name:UIKeyboardDidShowNotification object:nil];

   [[NSNotificationCenter defaultCenter] addObserver:self
         selector:@selector(keyboardWillBeHidden:)
         name:UIKeyboardWillHideNotification object:nil];

}



// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
 {
   NSDictionary* info = [aNotification userInfo];
   CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;

    // If active text field is hidden by keyboard, scroll it so it's visible
   // Your application might not need or want this behavior.
   CGRect aRect = self.view.frame;
   aRect.size.height -= kbSize.height;
   if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
    CGPoint scrollPoint = CGPointMake(0.0, activeField.frame.origin.y-kbSize.height);
    [scrollView setContentOffset:scrollPoint animated:YES];
   }
  }



// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{  
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
}
于 2013-02-28T03:37:02.333 に答える