i'm using uiwebview to display a very basic html page with just text. i want to support landscape and portrait orientations but i'm having a problem with resizing when the orientation changes. specifically, when the iphone is rotated to landscape, it zooms in on the text (i want the text size to remain the same and for it to fill the wider horizontal space). when it is rotated back to portrait, the text returns to the correct size but now it flows off the page to the right.
i think the solution is to reload the page with each change in orientation. is there a way to reload the page each time the iphone is rotated?
You can call reload on the web view when the view controller receives either of these methods:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
You could try setting scalesPageToFit=NO in the web view. You have fairly fine grained control of the webview from the html. Look at the viewport and other meta tags you can use.
Related
Is there a way to force ipads and iphones to render the web based layout in landscape mode only?
You have to prevent the view from rotating with:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
then you have to initiate the view in landscape this way you will prevent the view from rotating.
You can't force Safari to stay in a specific orientation, but you can detect it.
body[orient="landscape"] or body[orient="portrait"] can be used in your CSS to render two different layouts. If you choose, one of them (portrait in this case) can display a "not optimized for this layout" screen of some sort.
I suppose you could try to do a -webkit-transform: rotate(-90deg) on the body of the page, but if the page scrolls that probably would not be feasible. If your layout was exactly the right size, though, it might look pretty close to correct.
I've made a site for iphone and all is fine except that I'd like the homepage to auto-scroll to the top when rotated to landscape. I have set the address bar to auto hide via javascript, so when the site loads in portrait the masthead is at absolute top of the page.
Currently what happens is when the device is set to landscape the page viewport shows pretty much the center two quarters of the page with the masthead no longer visible. I would like the page to automatically scroll to the top so the masthead is visible.
Is there a bit of JS to make this possible? or maybe it can be done with UIScrollView - of which i'm new to.
Thanks in advance
I have an UIWebView that has an youtube's embed code (iframe). I'd like to enable both portrait and horizontal orientation for the video player, but portrait mode only for the UIWebView itself.
How can I achieve this?
The UIWebView displays its content by its orientation. There is no (easy) way to conditionally change which orientations the UIWebView allows based on its content. The only way I can imagine this working is by parsing the HTML of the web view and based on its content, allowing or disallowing certain orientations.
Regardless of all this, I would suggest either allowing both portrait and landscape for both, or only allowing portrait. This would be confusing to users if you only sometimes allowed landscape.
This is a pretty weird error. I have a tab bar controller, with a nested navigation controller, which then has your standard tableview. When you click on a cell a new view is pushed onto the controller. This is a regular view with a nested uiwebview, that takes the entire view up.
When entering that view in portrait mode it looks great, when you rotate it to landscape it looks great, and back to portrait again is good.
But when you enter that view using landscape it looks great but rotating to portrait doesn't seem to resize, the width is still too wide and the text is larger.
I've tried
1.webView.frame = self.view.frame;-That didnt seem to change its behavior
2.Both the view and the webview are set to autosize and like i said it works when starting in portrait
3.[webView setFrame:CGRectMake(0, 0, 320,411)]; when rotating to portrait from landscape. This is really weird, it makes the webview consume half the screen. Font is still large.
4.I've changed the autoresize to disabled, manually resize them on orientation change and then do a [webView reload];
Ive tried various other things and combinations of things. This problem is consistent across all of my subviews that are webviews.
I am sort of new so please be as specific as you can.
Use <meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0;'> in the head of your html
I'm building an app that uses a UIView that contains a UIScrollView within it so that when the keyboard shows up, users can still scroll downwards to see the content within the view. It seems like I have gotten everything perfectly set up but when I rotate, everything goes completely unusable. The views are all out of place and I am unsure what's the strategy to handle this. I have the views autoresizing but they don't seem to be doing it correctly.
Should I manually check to see if the rotations have occurred and reset the frame without autoresizing or is there a way that I can accomplish this with auto resizing?
The situation is this:
Portrait mode - form fits fine. When keyboard shows up, scroll view is resized but form does not.
Landscape mode - form doesn't fit fine and when keyboard shows up, scroll view is messed up.
Do I need to resize the form view when rotated to landscape mode?
Thanks!
You can reposition things back to original by using:
-(void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
//reposition code
}
I have an issue where I want the keyboard to resign upon the ipad rotating.
If the keyboard is open in portrait, and I rotate to landscape, the keyboard appears in landscape.
HOW DO I RESIGN the keyboard when I rotate!
TY