2011-10-20 1 views
15

Come molti di voi sanno, iOS 5 ha introdotto una tastiera divisa per digitare i pollici. Sfortunatamente, ho un'interfaccia utente che dipende dal normale layout di tastiera a schermo intero. Uno dei miei controller di visualizzazione presenta all'utente un foglio di testo, e se fanno clic su un campo di testo che sarà coperto dalla tastiera, scorre verso l'alto insieme alla tastiera. Questa azione non è necessaria con la tastiera divisa.Verificare la presenza di una tastiera divisa

C'è un modo per verificare quale layout di tastiera è in uso prima che venga visualizzato?

Grazie!

+0

Apprezzerei un aggiornamento su come avete risolto questo! –

+0

provo risposta su questa domanda nel [qui] [1] [1]: http://stackoverflow.com/a/17567217/887325 – Bimawa

risposta

17

Quando la tastiera è ancorata, verrà sollevato il numero UIKeyboardWillShowNotification. Se la tastiera è divisa o sganciata, non vengono sollevate notifiche sulla tastiera.

Se una tastiera è agganciata, UIKeyboardWillShowNotification sarà sollevato, e la seguente sarà vero:

[[[notification userInfo] valueForKey:@"UIKeyboardFrameChangedByUserInteraction"] intValue] == 1 

Se una tastiera è sganciato, verrà sollevato UIKeyboardWillHideNotification, e la dichiarazione di cui sopra sarà anche vero.

L'utilizzo di queste informazioni è stato sufficiente per codificare la mia interfaccia utente.

Nota: questa potrebbe essere una violazione delle linee guida di Apple, non sono sicuro.

+0

il valore per 'UIKeyboardFrameChangedByUserInteraction'is non corrette al iOS7 – Daniel

1

Le notifiche che vengono pubblicati quando appare la tastiera o cambia la sua posizione (UIKeyboardWillShowNotification, UIKeyboardWillChangeFrameNotification) contengono un dizionario userInfo con la cornice della tastiera (UIKeyboardFrameEndUserInfoKey) che consente di posizionare correttamente gli elementi dell'interfaccia utente, a seconda della dimensione reale e posizione della tastiera.

5

UIKeyboardFrameChangedByUserInteraction il tasto non torna 1 tutto il tempo in cui la tastiera si divide.

Di seguito sono riportati i valori chiave del dizionario delle informazioni utente completo su UIKeyboardDidShowNotification/UIKeyboardDidHideNotification.

2012-07-11 11:52:44.701 Project[3856:707] keyboardDidShow: { 
    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {1024, 352}}"; 
    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {512, 944}"; 
    UIKeyboardCenterEndUserInfoKey = "NSPoint: {512, 592}"; 
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{-352, 0}, {352, 1024}}"; 
    UIKeyboardFrameChangedByUserInteraction = 0; 
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{0, 0}, {352, 1024}}"; 
} 

2012-07-11 11:52:45.675 Project[3856:707] keyboardDidHide: { 
    UIKeyboardBoundsUserInfoKey = "NSRect: {{0, 0}, {1024, 352}}"; 
    UIKeyboardCenterBeginUserInfoKey = "NSPoint: {512, 592}"; 
    UIKeyboardCenterEndUserInfoKey = "NSPoint: {512, 944}"; 
    UIKeyboardFrameBeginUserInfoKey = "NSRect: {{0, 0}, {352, 1024}}"; 
    UIKeyboardFrameChangedByUserInteraction = 0; 
    UIKeyboardFrameEndUserInfoKey = "NSRect: {{-352, 0}, {352, 1024}}"; 
} 

Invece è possibile utilizzare UIKeyboardCenterBeginUserInfoKey o UIKeyboardCenterEndUserInfoKey chiavi per essere avvisato quando si divide la tastiera.

Spero che questo aiuti!

+5

_Questo ha funzionato per me_ [iPad Split-Keyboard e (Missing) Notifications] (http://adevelopingstory.com/blog/2012/05/the-ipad-split-keyboard-and-missing-notifications.html), – Zeeshan

9

Questa è la soluzione che funziona con iPad tastiere divise (in origine dal blog collegato a commento di Zeeshan)

[[NSNotificationCenter defaultCenter] 
    addObserverForName:UIKeyboardDidChangeFrameNotification 
    object:nil 
    queue:[NSOperationQueue mainQueue] 
    usingBlock:^(NSNotification * notification) 
{ 
    CGRect keyboardEndFrame = 
    [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; 

    CGRect screenRect = [[UIScreen mainScreen] bounds]; 

    if (CGRectIntersectsRect(keyboardEndFrame, screenRect)) 
    { 
     // Keyboard is visible 
    } 
    else 
    { 
     // Keyboard is hidden 
    } 
}]; 
+1

Great , ma invece di controllare che la tastiera intersechi il frame della vista corrente, controlla se è sullo schermo: CGRect screenRect = [[UIScreen mainScreen] bounds]; if (CGRectIntersectsRect (keyboardEndFrame, screenRect)) ... –

+0

@MasonLee Aggiornato come da commento. Grazie! – Robert