开发者

Scroll to new textfield when choosing a new textfield

开发者 https://www.devze.com 2023-03-08 15:30 出处:网络
I have followed apple\'s guide Managing keyboard It works like a charm u开发者_运维百科nless you are already writing in a textfield and tab in a new textfield.

I have followed apple's guide Managing keyboard

It works like a charm u开发者_运维百科nless you are already writing in a textfield and tab in a new textfield.

This is the function in the example that take cares of the scrolling. But it's never being called because it's already up?

- (void)keyboardWasShown:(NSNotification*)aNotification;

Anyone know a good solution to this problem?


in .h

CGSize keyboardSize;

and

- (void)keyboardWasShown:(NSNotification*)aNotification;

in .m

- (void)keyboardWasShown:(NSNotification*)aNotification {
    NSDictionary* info = [aNotification userInfo];
    if (info) {
            /* Can get keyboard Size */
            keyboardSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey]
    } 

    /* Animation code */

}

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    activeField = textField;
    [self keyboardWasShown:[NSNotification notificationWithName:UIKeyboardDidShowNotification object:nil]];
}

Thanks to vakio.


interface:

CGSize keyboardSize;
BOOL keyboardIsVisible;

implementation, keyboardWasShown:

keyboardSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
keyboardIsVisible = YES;
// Move ScrollView

keyboardWillBeHidden:

keyboardIsVisible = NO;

textFieldDidBeginEditing:

if (keyboardIsVisible) {
    // Move ScrollView
}
0

精彩评论

暂无评论...
验证码 换一张
取 消