简体   繁体   中英

UIButton won't move correctly

I'm trying to programatically move two buttons:

When the "Sign up" button is clicked, the login/sign up buttons will go down a few pixels (to make room for other input fields). If I click it, the buttons go down like they should, everything is working fine. If I select the first field, everything is also fine. But when I switch the selected field from username to password, the buttons go back up! Here's a screenshot: 在此输入图像描述

(the login/sign up buttons were moved a few pixels lower, but when I switched focus from one textfield to another, they went back). Also, the two input fields don't have any handlers attached to them (I've also tried adding two blank new fields, the same thing happened). Here's the code I'm using to move the buttons:

-(void)moveButtonTo:(UIButton *) button y:(int) y {
    [self moveButtonTo:button x:button.frame.origin.x y:y ];
}
-(void)moveButtonTo:(UIButton *) button x:(int) x y:(int) y {
    CGPoint center = CGPointMake(x + button.frame.size.width/2.f, y + button.frame.size.height/2.f);
    [UIView animateWithDuration:1 animations:^{
        [button setCenter:center];
    }];
}

And then move the buttons like this:

[self moveButtonTo:loginButton y:250];
[self moveButtonTo:signupButton y:250];

Did anyone encounter this before or knows how to fix it?

Uncheck autolayout and set size inspector like this 在此输入图像描述

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