简体   繁体   中英

Why does this orientation code not work?

I have a simple UIWebView nested in a ViewController it is presented modally off a navigation controller.

Structure as follows: TableViewController -> TableViewController -> Modal (WebView presented) -> Modal (options, presented via gesture, page curl)

All views handle all orientations except the one with the WebView on it, it is to handle its orientation via configuration.

The controller with the web view has the following orientation code:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    BOOL orientationSwitch = NO;

    if([self.webApp.orientationLandscape boolValue] &&
       UIInterfaceOrientationIsLandscape(interfaceOrientation))
        orientationSwitch = YES;

    if([self.webApp.orientationPortrait boolValue] &&
       UIInterfaceOrientationIsPortrait(interfaceOrientation))
        orientationSwitch = YES;

    return orientationSwitch;
}

Now the intention is that you can set some options as to if the view should react to the orientation changes. And for the most part it works, however I have a modal popup where you can choose to dismiss the modal that contains the web view. Once this happens, it seems the orientation is locked for the entire app. All other views subsequently do not respond to any form of rotation.

Any ideas?

Thanks

Here's something to try. Register with the UIDevice for UIDeviceOrientationDidChangeNotification and tell it to start generating notifications. When a notification comes in, call the UIViewController class method attemptRotationToDeviceOrientation (iOS 5 only).

Also it might help to read this tech note, as you may be doing something wrong here: https://developer.apple.com/library/ios/#qa/qa1688/_index.html

first, make sure in your project settings are the right supported orientations clicked (targets -> appname ->summary)

I don't know why this is happening, but I had a similar issue quite a while ago. That long time ago, ios 3.2 or something. I created a ViewRotatorController which only implements the -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {} method. Every other ViewControllers inherits that. Just let your webappview has a other implementation of this. It is probably not the best solution but it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM