Reputation: 611
I came to a point where I was able to lock the horizontal scroll as I wanted however when I rotate from landscape to portrait the content is still to large. I need to resize/scale it down myself but I don't know how to so far I use this :
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *fullURL = @"http://igo.nl";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
_webView.scrollView.bounces = false;
_webView.scalesPageToFit = YES;
_webView.contentMode = UIViewContentModeScaleAspectFit;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(fromInterfaceOrientation == UIInterfaceOrientationPortrait)
{
//_webView.scrollView.contentSize = CGSizeMake(320, _webView.scrollView.contentSize.height);
}
else
{
//[_webView reload];
_webView.bounds = CGRectMake(0, 0, 320,_webView.bounds.size.height);
_webView.frame = CGRectMake(0, 0, 320, _webView.frame.size.height);
_webView.scrollView.contentSize = CGSizeMake(320, _webView.scrollView.contentSize.height);
}
}
EDIT: What I seem to need is that the content is zoomed out
Upvotes: 0
Views: 1137
Reputation: 3399
Use the delegate methods of UIWebViewDelegate
@interface YOUR_CLASS : PARENT_CLASS <UIWebViewDelegate>
In viewDidLoad
...
[_webView setDelegate:self];
...
Call the delegate method
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[webView.scrollView setContentSize: CGSizeMake(webView.frame.size.width, webView.scrollView.contentSize.height)];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[_webView reload]; //Or use meta tag
[_webView.scrollView setContentSize: CGSizeMake([_webView.scrollView.contentSize.width, _webView.scrollView.contentSize.height)];
}
You have to add meta
tag to your HTML
file
<meta name="viewport" content="width=device-width" />
or simply reload the webView
[_webView reload];
Upvotes: 2
Reputation: 1558
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation==UIInterfaceOrientationPortrait && toInterfaceOrientation!=UIInterfaceOrientationPortraitUpsideDown )
{
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation ==UIInterfaceOrientationLandscapeRight)
{
}
}
Upvotes: 0
Reputation: 603
try in
-(void)viewWillLayoutSubviews
{
------
}
calculate using
self.view.bounds.size.width,
self.view.bounds.size.height
Upvotes: 0