Search code examples
iosobjective-ccocoa-touchuibutton

can not move buttons


I have a little problem that my buttons doesn't move when I am using a code that should move the button.

ViewControlle.h:

@property (strong, nonatomic) IBOutlet UIButton *button1;
@property (strong, nonatomic) IBOutlet UIButton *button2;

ViewController.m:

@implementation GameViewController
@synthesize button1,button2;

code which should move the buttons:

button1.center=CGPointMake(button1.center.x, button1.center.y-10);
button2.center=CGPointMake(button2.center.x, button2.center.y+10);

why does the code not work or am I doing something wrong?


Solution

  • Because autolayout did not happen before view did load it will reset your locations.

    when - (void)viewDidLayoutSubviews gets called its done so place your code here.