views:

4034

answers:

4

I'm using a UIWebView with text in it. When the iPhone is rotated to landscape, text doesn't fill the now wider UIWebView width. I'm using P (paragraph) tags, which should not affect content filling landscape's width. The line breaks that are visible in portrait remain the same in landscape. In Interface Builder, I haven't changed anything. In the IB Inspector, Web View Size has all solid bars under AutoSizing, which means it should fill to the landscape width right?

A: 

I have the same problem. Reloading does not work, the only thing that seems to help a bit is to add the following line to the code:

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth;

(I place it in the willAnimateFirstHalfOfRotationToInterfaceOrientation function)

It still keeps a small white margin at the right, but its far better than the default. Note: you should apply this on the self.view and not on the UIWebView instance, that won't work.

Waiting for a solution from Apple..

Pieter

Pieter Kubben
This didn't make any difference for me.
4thSpace
A: 

Now tried around with the same problem, finally did it after looking detailed at "WhichWayIsUp"-Sample from Apple.

To keep it short:

1) Disable in the View Inspector the |--| and <-->

2) `switch the View Mode from the Webview to "Aspect Fill"

Et voila ;)

Keep the vibes, Maniac

A: 

Here is a tweak though not a good thing to do, and something should be handled by apple itself

As you've noticed that things workfine when WebView is initialized in portrait and then you turn it to landscape. So.. what you can do is always initialize your webview with portrait bounds, add a selector which calls back after 2~3 seconds and sets the frame of webView according to your requirement.

Now as the contents started loading when the frame size of your webview were according to portrait (say 320,460) so converting your webview to landscape will automatically adjust your web view if you have this line in your code

[webViewObjet_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

Below is the snippet of code

-(id) initWithFrame:(CGRect)frame { if(self = [super initWithFrame:frame]) { webViewObjet_ = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; ........ }

  • (void)webViewDidStartLoad:(UIWebView *)webView { .....

    [self performSelector:@selector(chuss) withObject:nil afterDelay:3]; // call the function chuss after 3 second }

-(void) chuss { webViewObjet_.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); [webViewObjet setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

}

San
A: 

This will sound strange, but it works:

If the UIWebView is inside a UINavigationController, it will all work just fine. I had the same problem, so I just wrapped it up in a UINavigationController and the problem was gone.

For some reason, UINavigationController makes rotations work like a charm.

Tal Bereznitskey