简体   繁体   中英

Appearing keyboard changes view's frame

in my app im tapping on a navigation bar button and as a response i move the view beneath the navigation bar 60 px down (the delta var in the code), and under the view that moves down, appears a UITextField and at the same time show the keyboard.

that's how i achieve it:

-(void)btnSearch_Click:(id)sender{
    float delta = _viewBtnSort.frame.size.height;
    CGRect rect = rectSearch;
    rect.origin.y += delta;

    [UIView animateWithDuration:0.3f animations:^{
       [_viewSearchResults setFrame:rect];
    }completion:^(BOOL finished) {
       [buttonSearch setEnabled:NO];
       [_txtFieldSearch becomeFirstResponder];
}];}

Problem

it works fine for a few times and then for some unexplained reason(couldnt find so far why), when the keyboard appears it pushes my view back up i and i dont get the effect i want.

anybody got any ideas? thanks!

so i kept looking for a fix, and did it using this iOS8: What's going on with moving views during keyboard transitions? answer.

i changed my constraint instead of the frame and now it seems to work fine.

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