2014-09-23 15 views
7

Ho un'interfaccia utente che necessita di alcune regolazioni di posizione quando viene visualizzata una tastiera.iOS8 UIKeyboardWillShowNotification Altezza tastiera di terze parti

Il seguente è utilizzato per rilevare quando una tastiera viene mostrato:

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

Nota: Ho provato sia con UIKeyboardWillShowNotification e UIKeyboardDidShowNotification

- (void)keyboardWillShow:(NSNotification *)n { 
    if (isKeyboardShowing) 
    return; 

NSDictionary* userInfo = [n userInfo]; 

// get the size of the keyboard 
CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size; 


// Animate keyboard shift 
[self.view layoutIfNeeded]; 

[UIView animateWithDuration:0.2f animations:^{ 
    // some animation here 
} completion:^(BOOL finished) { 
    if (finished) 
     isKeyboardShowing = YES; 
}]; 

Per l'abitudine tastiere rendimenti dimensioni della tastiera {320 , 0}. Dato che le tastiere possono avere altezze diverse ora, non posso avere valori statici per cambiare l'interfaccia quando viene presentata la tastiera.

Si tratta di un problema con ios8? e ci sono altri metodi per ottenere dinamicamente l'altezza della tastiera?

Edit: Questa è l'userInfo Dict:

{name = UIKeyboardDidShowNotification; userInfo = { 
    UIKeyboardAnimationCurveUserInfoKey = 7; 
    UIKeyboardAnimationDurationUserInfoKey = "0.25"; 
    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {320, 0}}"; 
    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {160, 568}"; 
    UIKeyboardCenterEndUserInfoKey = "NSPoint: {160, 568}"; 
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 568}, {320, 0}}"; 
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 568}, {320, 0}}"; 
}} 

Grazie in anticipo.

risposta

11

Usa

CGSize keyboardSize = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; 

per ottenere la dimensione effettiva della tastiera

Problemi correlati