Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView rearranging on rotation

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?

like image 698
user2786037 Avatar asked Feb 03 '26 20:02

user2786037


1 Answers

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.

like image 189
Nikita Took Avatar answered Feb 05 '26 12:02

Nikita Took



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!