Disabling autorotate for a single UIView

前端 未结 4 1808
野趣味
野趣味 2020-12-17 00:41

Okay, this seems like it should be relatively simple, but I\'ve been Googling for the better part of an hour, and can\'t seem to find what I need.

I have a view cont

4条回答
  •  囚心锁ツ
    2020-12-17 01:21

    If you don't want temporary rotations of the background view after which the background is changed to have the correct orientation, you'll need to turn off Autorotation for the View. No two ways about it.

    You would need to handle the rotation of the buttons yourself. You can either make a nice layout or put them on for example a Scrollview and just resize that.

    Either way, you'd need to add an observer to rotate it yourself,

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)
                                                     name:UIDeviceOrientationDidChangeNotification object:nil];
    

    And in didRotate you do the resize, with a nice animated transition, if you like.

    - (void) didRotate:(NSNotification *)notification {
     int ori=1;
        UIDeviceOrientation currOri = [[UIDevice currentDevice] orientation];
        if ((currOri == UIDeviceOrientationLandscapeLeft) || (currOri == UIDeviceOrientationLandscapeRight)) ori=0;
    }
    

    Hope that sorts you. If Navigation bars or status bars cause the View to get tucked in under the top bar, there are ways to fix that.

提交回复
热议问题