Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Is the idea behind this view to keep it attached to the top of the default system keyboard to extend the basic input functionality? If this is the case, which it sounds like it is, there is a much simpler built-in solution. Any class inheriting from UIResponder (any class that triggers the keyboard's appearance) can declare an <a href="http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html" rel="nofollow">Input Accessory View</a> that will automatically stay attached to the top of the default keyboard.</p> <p>EDIT: Okay, so that's not your situation. In that case, I'll share a method I've used in a few apps to translate various things with the keyboard's appearance manually. First, I prefer to get the details of the transformation from the system, instead of hardcoding values like 216. This keeps it nice and future-proof, in the (unlikely) event the keyboard's size is ever changed by Apple. This info is available in an NSNotification. To get the notification, register for it somewhere like this:</p> <pre><code>- (void)viewWillAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } - (void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; } </code></pre> <p>Then, in the handlers:</p> <pre><code>- (void)_keyboardWillShow:(NSNotification *)notification { [self _animateWithKeyboardNotification:notification]; } - (void)_keyboardWillHide:(NSNotification *)notification { [self _animateWithKeyboardNotification:notification]; } </code></pre> <p>And, for the main act:</p> <pre><code>- (void)_animateWithKeyboardNotification:(NSNotification*)keyboardNotification { /* Animates a view with an animation constructed from the system keyboard * animation properties. The animation is a vertical translation to compensate * for the area now covered by the keyboard. */ UIViewAnimationCurve curve = [[keyboardNotification.userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]; NSTimeInterval duration = [[keyboardNotification.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; CGFloat keyboardHeight = [[keyboardNotification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; // Set the transform based on the keyboard action: Translate up if showing, reset to identity when hiding CGAffineTransform animationTransform; if ([keyboardNotification.name isEqualToString:UIKeyboardWillShowNotification]) animationTransform = CGAffineTransformMakeTranslation(0, -keyboardHeight); } else if ([keyboardNotification.name isEqualToString:UIKeyboardWillHideNotification]) { animationTransform = CGAffineTransformIdentity; } // Apply the animation. [UIView animateWithDuration:duration delay:0.0f options:curve animations:^ { self.view.transform = animationTransform; } completion:^ (BOOL finished) { // Completion handler, if needed. }]; } </code></pre> <p>Now, with this exact method, I'm translating the entire view. You can tweak it to only translate your input view if you need to, or make any other small adjustments. I like this approach for its durability.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload