All, I have a UIWebView inside a ViewController. The controller is hooked up appropriately and segues properly from the previous tableview. However, I am struggling to accomplish two things: 1. Force the UiWebView (well, the entire scene) to landscape (I am displaying maps from a url) and not allow user rotation, and 2. Have the webview displayed within the constraints of the device. Right now, the UIWebView runs off the screen when displayed as a landscape.
I have tried to reset constraints, update missing constraints, direction lock in storyboard, view>mode>aspectfit in storyboard and forcing it to landscape in the viewcontroller method file (setting to aspectfit instead of aspectfill).
I have read previously questions on here which said it was not possible in previous iOS versions to lock just one scene to portrait/landscape. I have found that this might have changed with iOS7.
I am seeking guidance on how to lock a view and to shrink the webpage displayed in uiwebview to fit the dimensions of the iphone app. Thanks
Four steps:
override the UINavigationController's preferredInterfaceOrientationForPresentation: method
(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
UIDevice *myDevice = [UIDevice currentDevice];
UIDeviceOrientation deviceOrientation = myDevice.orientation;
if (deviceOrientation == UIDeviceOrientationLandscapeLeft)
{
return UIInterfaceOrientationLandscapeRight;
}
else if (deviceOrientation == UIDeviceOrientationLandscapeRight)
{
return UIInterfaceOrientationLandscapeLeft;
}
else {
return UIInterfaceOrientationLandscapeLeft;
}
}
set your UIViewController that has the UIWebView as the rootViewController of your subclassed UINavigationController
If the above doesn't work, try applying the following to your tableViewController (i.e. the viewController that will present your UINavigationController subclass.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
You may also need to add these settings under Target > General.
That seems to be all that I did to get a forced landscape orientation working in my app.