Make iOS page scrollable when keyboard is on

I have an iOS page for registration, and I want to make it scrollable if the keyboard is turned on, because at the moment I can not go to the registration button at the end of the page, and the keyboard hides the button.

Is there any reasonable solution?

+4
source share
1 answer

There are many solutions to solve your problem. From use UIScrolViewto changing the scope or limitation.

If you want to use UIScrolView, you must insert the registration form UIViewin UIScrolViewand set the size of the content.

, .

, , . :

- (void)registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWasShown:)
                                                 name:UIKeyboardDidShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillBeHidden:)
                                             name:UIKeyboardWillHideNotification object:nil];

}

(keyboardWasShown keyboardWillBeHidden) contentInsets.

contentInsets:

- (void)keyboardWasShown:(NSNotification*)aNotification
{
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;
}

- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
    UIEdgeInsets contentInsets = UIEdgeInsetsZero;
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;
}

, , , UIScrolView.

+1

All Articles