How do I adjust the keyboard to the size of the view?

sorry if the title is not clear enough, poorly explain:

I have some code that I am using to adjust the size of the view to fit the keyboard, because when you type the selection and you come up to the keyboard, you and the text indicator bounce so that the text doesn't follow the keyboard.

This is my code to transform this:

-(void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor clearColor];
    UIToolbar *blurbar = [[UIToolbar alloc] initWithFrame:self.view.frame];
    blurbar.barStyle = UIBarStyleDefault;
    [self.view addSubview:blurbar];
    [self.view sendSubviewToBack:blurbar];

    // Subscribe to keyboard notifications
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];

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

#pragma mark - UIKeyboard

- (void)keyboardWillShow:(NSNotification *)notification
{
    if ([self.myTextView isFirstResponder]) {
        NSDictionary *info = [notification userInfo];
        CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
        CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];

        [UIView animateWithDuration:duration
                         animations:^{
                             self.myTextView.contentInset = UIEdgeInsetsMake(self.myTextView.contentInset.top, self.myTextView.contentInset.left, kbSize.height, 0);
                             self.myTextView.scrollIndicatorInsets = UIEdgeInsetsMake(self.myTextView.contentInset.top, self.myTextView.scrollIndicatorInsets.left, kbSize.height, 0);
                         }];
    }
}

- (void)keyboardWillHide:(NSNotification *)notification
{
    if ([self.myTextView isFirstResponder]) {
        NSDictionary *info = [notification userInfo];
        CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];

        [UIView animateWithDuration:duration
                         animations:^{
                             self.myTextView.contentInset = UIEdgeInsetsMake(self.myTextView.contentInset.top, self.myTextView.contentInset.left, 0, 0);
                             self.myTextView.scrollIndicatorInsets = UIEdgeInsetsMake(self.myTextView.contentInset.top, self.myTextView.scrollIndicatorInsets.left, 0, 0);
                         }];
    }
}

      

The problem is that now I am using a non-full size that will represent the keyboard, which looks like this:

enter image description here

and here i cant get an idea to set up ... i would like some help, thanks.

+3


source to share





All Articles