mmmbaileys mmmbaileys - 3 years ago 183
iOS Question

Move UIView Programmatically

My app displays banner ads at the bottom of the screen.

Above these ads are several UIViews/UIImageViews etc.

If the user removes the ads, via IAP, there is an empty gap where the banner used to be, as expected.

However, I would like to move these views down vertically, so as to reduce the obvious gap in the screen.

The code I've been trying doesn't seem to be working -

UIView *moveView = [self.view viewWithTag:5];
CGRect frame = moveView.frame;

[moveView removeFromSuperview];

frame.origin.y = frame.origin.y + 25.0;
moveView.frame = frame;

[self.view addSubview:moveView];

Answer Source

The answer below suggested to remove autolayout, however I needed autolayout for my storyboard.

I simply needed to remove the autolayout for one UIView.

What I ended up using was

[moveView settranslatesautoresizingmaskintoconstraints:YES]

This simple line allowed me to move my view around without worrying about autolayout.

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