简体   繁体   中英

What is a good practice to adjust/moving view up and down when keyboard is shown, without using a scroll view(iOS)?

What is a good practice/way to adjust/moving view up and down when keyboard is shown, without using a scroll view?

I've posted this because my method was not working properly, and I desperately need a method that is safe and works.

Have you tried as like below?

- (void)viewDidLoad
{
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];

    [center addObserver:self selector:@selector(keyboardDidAppear) name:UIKeyboardDidShowNotification object:nil];

    [center addObserver:self selector:@selector(keyboardWillDisAppear) name:UIKeyboardWillHideNotification object:nil];

}

-(void)keyboardDidAppear
{
    CGRect frame = view.frame;

    frame.origin.y -= 214.0;

    view.frame = frame;
}

-(void)keyboardWillDisAppear
{
    CGRect frame = view.frame;

    frame.origin.y += 214.0;

    view.frame = frame;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM