Reputation: 3
Hi i'm struggling with the auto layout in xcode5. Maybe I'm totally wrong and there is another way to get my desired result.
take a look:
this is my portrait view how i made it in Interface Designer
this is how i want the button to stay and rotate in landscape
So is there a way to accomplish this in interface builder and auto layout or is there another way to go?
Upvotes: 0
Views: 392
Reputation: 4012
Yes, there is.
There is 2 ways: short and "right".
Short way
Add notification in viewDidLoad (and don't forget to unsubscribe in dealloc)
// don't forget the first line, otherwise you won't ger orientation. [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
Add constraint Bottom spacing View - Superview
If orientationChanged method set required value:
self.constaint.constant = UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ? 10 : 200;
Right way
All code dealing with constraints should go to - (void) updateConstraints of UIView.
Upvotes: 1
Reputation: 535139
You're asking the button to move from all the way at the bottom to all the way at the top. That's not going to happen automagically! You'll to have move the button yourself in code. Implement viewWillLayoutSubviews
on your view controller and position the button there.
Upvotes: 0