4
votes

I browsed through most of the questions and tried almost everything. But bad part is that the issue is still there.

I have a UIVIew which is always launched in landscape mode and I am presenting a second view (detailView) as a full screen modal view.

The detailview has a UIwebview on top of it.

When I present the detailView as a modal view, the webview is being shown in portrait mode.

I am returning "YES" in shouldAutoRotateToInterfaceOrientation and also have set autoresize , autoresizingMask and scalePageToFit properties.

When I rotate the device, and when the detailView is in front, the webview arranges to landscape properly.

The issue is only when I present the modalView for the first time.

Rotating the device is adjusting the layout properly.

4
And I have also tried setting the status bar in modal view's viewWillAppear., i.e, [[UIApplication sharedApplication] setStatusBarOrientation: self.interfaceOrientation]... Even this doesnt workKiran Kulkarni
:try this - crate one custom viewController(say - FirstViewController) of class UIViewController. in this VC, support both orientations (Port and Land). Then create SecondViewController which will be subclass of FirstViewController, obviously in this u will create UIView with landscape mode and do same further as u did.Nayan
The termins landscape or portrait mode are related to UIViewController but not to UIView. So could you clarify what do you mean under portrait mode of UIWebView. Which method do you use to show UIWebView on top of detailview?onegray

4 Answers

3
votes

As far as I am aware ModalViews on the iPhone do not support Landscape View. The case may be different for iPhone 5.

But it sounds like you are setting the ModalView not the WebView to landscape, I'd suggest a different approach to handling this.

For Example you could animate the DetailView in like a ModalView so it starts in the correct orientation

1
votes

If you are running your app on iOS 6 you will need the following code in the modal view controller to support the landscape orientation:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL) shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}

Also, make sure you are testing on the actual device as opposed to the simulator because auto-rotation behaves differently on the simulator.

0
votes

That will do the trick:

CGAffineTransform transform = CGAffineTransformIdentity;
webView.transform = CGAffineTransformRotate(transform,-M_PI/2);
-1
votes

OK. First of all, the question I had posted was not clear. My question was that, when I load a webview, in portrait, it was loading the webview elements in landscape mode(CSS), and was getting loaded as portrait mode(CSS) in landscape orientation.

Turns out that I was not applying the correct CSS style.

The fix I did was: In ViewDidLoad and willAnimateRotation method, I am posting a notification to my javascript to update the style based on orientation :)