我来到了能够锁定水平滚动的地方,但是当我从横向旋转到肖像时,内容仍然很大。我需要自己调整大小/缩小它,但我不知道到目前为止如何使用它:
- (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);
}
}
编辑: 我似乎需要的是内容缩小
答案 0 :(得分:2)
使用UIWebViewDelegate
@interface YOUR_CLASS : PARENT_CLASS <UIWebViewDelegate>
在viewDidLoad
...
[_webView setDelegate:self];
...
调用委托方法
- (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)];
}
您必须将meta
标记添加到HTML
文件
<meta name="viewport" content="width=device-width" />
或只是重新加载webView
[_webView reload];
答案 1 :(得分:0)
尝试
-(void)viewWillLayoutSubviews
{
------
}
使用
计算self.view.bounds.size.width,
self.view.bounds.size.height
答案 2 :(得分:0)
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation==UIInterfaceOrientationPortrait && toInterfaceOrientation!=UIInterfaceOrientationPortraitUpsideDown )
{
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation ==UIInterfaceOrientationLandscapeRight)
{
}
}