我已经达到了可以锁定水平滚动条的地步,但是当我从横向旋转到纵向时,内容仍然很大。我需要自己调整大小/缩小它,但到目前为止我不知道如何使用它:
- (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);
}
}
编辑: 我似乎需要的是内容被缩小
最佳答案
使用UIWebViewDelegate
的委托(delegate)方法
@interface YOUR_CLASS : PARENT_CLASS <UIWebViewDelegate>
在viewDidLoad
...
[_webView setDelegate:self];
...
调用委托(delegate)方法
- (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];
关于ios - UIWebView 内容如何调整大小/缩放呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22909107/