Reputation: 381
Hi i have a portrait design of my app and i want to change this design when the user rotate the device.
Something like that:
Portrait:
Button 1 - Button 2
Button 3 - Button 4
Landscape:
Button 1 - Button 2 - Button 3 - Button 4
I don't know if the next way is the best:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
- (void) didRotate:(NSNotification *)notification{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeLeft) {
HERE CHANGE THE CONSTRAINS
}
}
Thanks for all.
Upvotes: 2
Views: 77
Reputation: 187
You can do this with using Size Class. i did this...
1. First Desigh Screen in wAny - hAny and set all Constrains
2. For Portrait select wCompact - hRegular and go to Size inspector
3. In Descendant Constrains there are many Constrains select one by one (double click on that)
4. you can see two + button. perss it and select wCompact - hRegular. it shownew field set Constrains (Size). do this for all Constrains.
5. Now for Landscape in storybord select wRegular - hCompact and do this same...
it is Work like if - else if condition... if (Portrait){ this } else if (Landscape) { this }
Upvotes: 1
Reputation: 5760
Why not use size classes? A size class is a property applied to any view or view controller that represents the amount of content that can be displayed in a given horizontal or vertical dimension. Size classes are available since iOS8. Already almost 90% of devices use iOS8 but of course it depends on requirements you have.
If you want to support older iOS versions, your approach is also good.
Upvotes: 0