DarkN3ss DarkN3ss - 1 year ago 100
iOS Question

UIView wont move programmatically

so there must be something simple I am missing because I just cant figure out how to move my UIView

This is what I have so far

my .m file

- (void)viewDidLoad
[super viewDidLoad];
[self buttonLayout];

UIView *theView = [self buttonGroup];
theView.center=CGPointMake(50, 50);

My .h file

@property (nonatomic, retain) IBOutlet UIView *buttonGroup;

So this is what I have so far and i just cant seem to get it to move at all
P.S i don't want it animated as i'm getting my layout to move to compensate for different iPhone screen sizes :)

Thanks for helping me out with this problem

Answer Source

I have not tested this, but it seems like you need to:

A) Remove the view from its parent.

B) Adjust the center of its 'frame', not the view.

C) Re-add the subview.

Like so:

UIView *theView = [self buttonGroup];
CGRect theFrame = theView.frame;

[theView removeFromSuperview];

theFrame.origin.x = 50.0;
theFrame.origin.y = 50.0;

theView.frame = theFrame;

[self.view addSubview:theView];

This should work with autolayout.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download