0
votes

I have been unable to find a solution to this problem anywhere. I am using Xcode 4.5 to write an iOS 6 app using storyboards. It uses a Navigation Controller to jump between several View Controllers with Navigation Bars, including a few that use a UIWebView to display a website. I have added code to the AppDelegate and various ViewController files to restrict the view to Portrait for most scenes in the app (since they really won't look good otherwise), but to allow Landscape view for the websites. And the Info.plist is configured allow all 4 orientations.

Everything works fine in the UIWebView scene; including rotation, scrolling and zooming - except for one thing: when I rotate from Portrait to Landscape, the horizontal dimension of the website stays locked at the horizontal dimension for the Portrait view - resulting in a large white space to the right of the website in the scene (see images below). I fixed a small (1/4") white space at the top of the UIWebView by selecting Layout: Wants Full Screen under View Controller in the Attributes Inspector. But I can't fix this.

I can supply relevant code or Storyboard settings if necessary. Can anyone help? Thank you.

Portrait view

Landscape view

1
Also, in Landscape mode, when I scroll up and down, the webpage's scrollbar appears and moves between the webpage and the whitespace. And, the whitespace itself will scroll up and down (with it's own scrollbar), revealing a small gray area above and a larger black area below the whitespace. As if there are two separately defined areas on the screen. That tells me something is constraining the horizontal size of the website for Landscape to the same size as it is for Portrait. I have tried changing the Autosizing struts & springs and other settings in the Size Inspector, with no effect.steveald
And, based on the behavior I described, it has been suggested that I have two webviews here, one created in the Interface Builder and one in the code. Do you think there might be something to that?steveald

1 Answers

0
votes

I solved adding this code, when application loads on viewDidLoad method:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
 [[NSNotificationCenter defaultCenter]
     addObserver:self selector:@selector(orientationChanged:)
     name:UIDeviceOrientationDidChangeNotification
     object:[UIDevice currentDevice]];

Then add this to your view controller:

- (void) orientationChanged:(NSNotification *)note
{
    UIDevice * device = note.object;
    switch(device.orientation)
    {
        case UIDeviceOrientationPortrait:
            _displayWeb.frame = CGRectMake (0, 0, 768, 1024);
            break;

        case UIDeviceOrientationPortraitUpsideDown:
            _displayWeb.frame = CGRectMake (0, 0, 768, 1024);
            break;
        case UIDeviceOrientationLandscapeLeft:
                _displayWeb.frame = CGRectMake (0, 0, 1024, 768);
            break;
        case UIDeviceOrientationLandscapeRight:
            _displayWeb.frame = CGRectMake (0, 0, 1024, 768);
            break;
        default:
            break;
    };
}

_displayWeb is your IBOutlet UIWebView, by the way this is using Xcode 4.6.1