Gabi Purcaru
Gabi Purcaru

Reputation: 31524

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: enter image description here

(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?

Upvotes: 1

Views: 263

Answers (1)

LE SANG
LE SANG

Reputation: 11005

Uncheck autolayout and set size inspector like this enter image description here

Upvotes: 3

Related Questions