Reputation: 505
I'm using storyboard for the project.
I have a top menu with 3 buttons (UIView
with 3 UIButton
's in it) with the same distance between them.
I would like to stretch this menu to maximum width on rotation and increase the distance between buttons.
I did the following:
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)orientation {
[super didRotateFromInterfaceOrientation:orientation];
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation)){
[self prepareLandscapeLayout];
}
}
- (void) prepareLandscapeLayout {
[[self topMenu] setFrame:CGRectMake(0, 0, IS_IPHONE_5 ? 568 : 480, 59)];
[[self cameraButton] setCenter:CGPointMake(232, 26)];
[[self settingsButton] setCenter:CGPointMake(288, 26)];
[[self videoList] setCenter:CGPointMake(340, 26)];
}
The prepareLandscapeLayout
function is called after rotation, but buttons remain in their original positions. I can also see how topMenu
stretches after rotation (I've changed the background color).
Are there any ideas on what I might be doing wrong?
Upvotes: 3
Views: 209
Reputation: 4012
As long as you DON'T want to use storyboard desig for rotation and constraints you should stop using "Autolayout"
See Interface Builder Document
in any controller on storyboard's right pane.
Upvotes: 1
Reputation: 5655
If the topMenu's frames is changing then write like.
- (void) prepareLandscapeLayout
{
[[self topMenu] setFrame:CGRectMake(0, 0, IS_IPHONE_5 ? 568 : 480, 59)];
[[self cameraButton] setFrame:CGRectMake(0,0,actualWidth,actualHeight)];
[[self settingsButton] setFrame:CGRectMake(topMenu.frame.size.width/3,0,actualWidth,actualHeight)];
[[self videoList] setFrame:CGRectMake((topMenu.frame.size.width/3)*2,0,actualWidth,actualHeight)];
}
Upvotes: 0
Reputation: 281
Center is relative to its original orientation and is calculated from frame (also relative to original orientation).
Instead, try changing the frames to be relative to the parent view's bounds (which update based on orientation).
Upvotes: 0