How do I force a specific UIInterfaceOrientation o

2019-01-22 19:32发布

Okay, so here's the situation:

I have an app in which I only want ONE specific view in a UINavigationController to have a landscape orientation. This view is a UIImageView that I'm capturing a signature on (THAT part works awesome). So, like this:

previous view --> signature view --> next view
 (portrait)        (landscape)       (portrait)

I can't seem to find a good way to force the device orientation to landscape on that signature screen. It'll never make sense to have a portrait orientation on the signature view because there's really not adequate room for signing in that screen width.

So, any bright ideas on how to accomplish this? I've considered possibly doing the signature view modally, thus breaking out of the navigation controller. Thoughts?

8条回答
看我几分像从前
2楼-- · 2019-01-22 19:57

The UINavigationController overrides the contain UIViewController orientation settings, so you have to create a custom subclass of UINavigationController with the following for 5.1:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[self topViewController] isKindOfClass:[SigCaptureViewController class]]) {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    } else {
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
}

For 6.0 and above you need:

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    if ([[self topViewController] isKindOfClass:[EXTRASigCaptureViewController class]]) {
        return UIInterfaceOrientationMaskLandscape;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

What I haven't figured out is how to make the force the UINavigationController to rotate. calling [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO] causes the status bar to rotate but doesn't cause the view to rotate.

查看更多
一夜七次
3楼-- · 2019-01-22 20:03

I think you can embed this view inside a view controller and overwrite the ShouldRotateToInterfaceOrientation method. Good luck!

查看更多
登录 后发表回答