2010-10-04 13 views
7

Für eine App, die ich für das iPad entwerfe, habe ich eine Bildlaufansicht mit einigen Textfeldern/Textansichten darin. Um alles sichtbar zu halten, passe ich die Eigenschaft contentSize der Bildlaufansicht an, um unten einen Puffer hinzuzufügen, der der Überlappung der Bildlaufleiste mit der Tastatur entspricht. Hier ist der Code (es gibt einige app-spezifische Sachen hier, aber hoffentlich nicht so viel, dass man keinen Sinn daraus machen kann):Die Größe des iPad Onscreen-Tastatur nach der Drehung

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 
    [nc addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 
    [nc addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; 
} 


- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 

    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; 
    [nc removeObserver:self name:nil object:nil]; 
} 

- (void)keyboardWillShow:(NSNotification *)aNotification 
{ 
    NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey]; 
    UIViewAnimationCurve curve; 
    [animationCurve getValue:&curve]; 

    NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey]; 
    NSTimeInterval duration; 
    [animationDuration getValue:&duration]; 

    NSValue *endingFrame = [[aNotification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey]; 
    CGRect frame; 
    [endingFrame getValue:&frame]; 

    [UIView beginAnimations:@"keyboardWillShow" context:bodyView]; 
    [UIView setAnimationCurve:curve]; 
    [UIView setAnimationDuration:duration]; 

    // Re-draw code here. 

    [UIView commitAnimations]; 
} 

- (void)keyboardWillHide:(NSNotification *)aNotification 
{ 

    NSValue *animationCurve = [[aNotification userInfo] valueForKey:UIKeyboardAnimationCurveUserInfoKey]; 
    UIViewAnimationCurve curve; 
    [animationCurve getValue:&curve]; 

    NSValue *animationDuration = [[aNotification userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey]; 
    NSTimeInterval duration; 
    [animationDuration getValue:&duration]; 

    [UIView beginAnimations:@"keyboardWillHide" context:bodyView]; 
    [UIView setAnimationCurve:curve]; 
    [UIView setAnimationDuration:duration]; 

    // Re-draw code here 

    [UIView commitAnimations];  
} 

Meine Frage ist: Was kann ich tun, um Größe der Tastatur während der Rotation? Ich bekomme keine Tastaturbenachrichtigungen, wenn das iPad gedreht wird, aber die Größe der Tastatur ändert sich erheblich. Idealerweise würde ich einfach die Höhe der Eigenschaft contentSize um den Betrag ändern, den die Tastatur im Querformat überlappt, aber ich sehe keinen guten Weg, dies zu tun, ohne die Höhe der Tastatur in beiden Ausrichtungen fest zu codieren, was ich nicht anwende Ich will es nicht tun.

Antwort

16

Ich habe versehentlich die Antwort auf dieses Debugging etwas anderes gefunden. Es stellt sich heraus, dass wenn das iPad von Hochformat zu Querformat rotiert, die Portait-Tastatur kurz vor dem Erscheinen der Querformat-Tastatur (und sendet ihre Benachrichtigung) aus (und sendet ihre Benachrichtigung). Solange Sie das erklären, sind Sie in Ordnung.

Verwandte Themen