2012-01-18 3 views
1

Messages.app ScreenshotのiOS 5のMessages.appキーボードアクセサリビュー行動

誰もが、私は実際にそれがアクセサリビューであることを信じていないよう行動に「アクセサリビュー」(逆コンマの中をエミュレートするために最善の方法を説明することができます)iOS 5のMessages.appには、キーボードの上部に固定されている印象を与えるビューが表示されますが、キーボードが閉じられると画面に残ります。

答えて

5

おそらく別のビューで、キーボードアニメーションと同じ長さのアニメーションを使用して再配置されます。

UIKeyboardWillShowNotificationとUIKeyboardWillHideNotificationを観察して、ハンドラでキーボードのアニメーションの長さとフレームを取得し、独自のアニメーションを開始してビューを再配置し、キーボードとともに移動するように見せます。私が使用している同様のコードは次のとおりです。

- (void)registerKeyboardNotifications { 
    // Register for keyboard notifications 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWillShow:) 
               name:UIKeyboardWillShowNotification 
               object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardWillHide:) 
               name:UIKeyboardWillHideNotification 
               object:nil]; 
} 

- (void)unregisterKeyboardNotifications { 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:UIKeyboardWillShowNotification 
                object:nil];  
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:UIKeyboardWillHideNotification 
                object:nil];  
} 

- (void)keyboardWillShow:(NSNotification*)aNotification { 
    NSDictionary* info = [aNotification userInfo]; 
    CGRect kbFrameBeginFrame = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; 
    CGRect kbFrameEndFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];  
    NSTimeInterval animDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];  
    UIViewAnimationCurve animCurve = [[info objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];  

    NSLog(@"\nFrame Begin = %@\nFrame End = %@\nAnimation Duration = %f\nAnimation Curve = %i", 
      NSStringFromCGRect(kbFrameBeginFrame), NSStringFromCGRect(kbFrameEndFrame), animDuration, animCurve); 

    _showKeyboard = YES; 
    [self adjustUIForKeyboard:kbFrameEndFrame.size animDuration:animDuration]; 
} 

- (void)keyboardWillHide:(NSNotification*)aNotification { 
    NSDictionary* info = [aNotification userInfo]; 
    CGRect kbFrameBeginFrame = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]; 
    CGRect kbFrameEndFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];  
    NSTimeInterval animDuration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];  
    UIViewAnimationCurve animCurve = [[info objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]; 

    NSLog(@"\nFrame Begin = %@\nFrame End = %@\nAnimation Duration = %f\nAnimation Curve = %i", 
      NSStringFromCGRect(kbFrameBeginFrame), NSStringFromCGRect(kbFrameEndFrame), animDuration, animCurve); 

    _showKeyboard = NO; 
    [self adjustUIForKeyboard:kbFrameEndFrame.size animDuration:animDuration]; 
} 

/** 
* Adjust the UI elements so that views are visible when keyboard is visible or hidden 
*/ 
- (void)adjustUIForKeyboard:(CGSize)keyboardSize animDuration:(NSTimeInterval)duration {  
    [UIView animateWithDuration:duration 
        animations:^(void) { 
         // When keyboard is showing we adjust up and vice versa for a hidden keyboard 
         if (_showKeyboard) { 
          // Set your view's frame values 
         } else { 
          // Set your view's frame values        
         } 
        } 
        completion:NULL]; 
} 
+0

私のここでの鍵は、通知からキーボードのアニメーションの詳細を抽出できるとは思わなかったことです。ありがとう。 –

+0

「スペルアウト」と言っていただきありがとうございます。 – Morkrom