UIWebView 不自动调整大小以适应屏幕
我有一个应用程序,它使用 UIViewController 在 UIWebView 中显示文章,其中一些有图像。我已将其设置为当单击图像时它会调用
- (void)displayImage:(NSInteger)i {
ImageViewController * imageVC = [[ImageViewController alloc] initWithImageId:i];
[self.navigationController pushViewController:imageVC animated:YES];
[imageVC release];
}
这会加载另一个 UIViewController。 我所有的观点对旋转的反应都很好。 ImageViewController 保持图像的比例,而 ArticleViewController 用文本填充屏幕。但是,每当我在查看 ImageViewController 时将屏幕旋转到横向模式并按后退按钮时。以前的 UIViewController 自动调整大小不正确,增加了文本的字体大小,而不是在一行上放置更多单词。
编辑:
这是一个文章视图控制器:
这是当您单击image:
现在,如果我们更改此处的方向...
并点击后退按钮,文章内容已被不适当地调整大小以适合窗口。
这可以通过转动 iPhone 两次来纠正。这就是文章横向显示时的样子。
该问题与 UIWebView 在当前不可见时无法适当自动调整大小有关。我可以做什么来解决这个问题?
I have an app that uses a UIViewController to display articles in a UIWebView, some of which have images. I have it set up so that when an image is clicked it calls
- (void)displayImage:(NSInteger)i {
ImageViewController * imageVC = [[ImageViewController alloc] initWithImageId:i];
[self.navigationController pushViewController:imageVC animated:YES];
[imageVC release];
}
This loads another UIViewController.
All of my views responds perfectly fine to rotations. The ImageViewController maintains the proportions of the image and my ArticleViewController fills the screen with text. However, whenever I rotate the screen to landscape mode while viewing my ImageViewController and press the back button. The previous UIViewController autoresizes incorrectly, increasing the font size of the text rather than putting more words on a line.
EDIT:
This is an article view controller:
This is the ImageViewController that comes up when you click the image:
Now if we change the orientation here...
And hit the back button, the article content has been inappropriately resized to fit the window.
This can be corrected by turning the iPhone twice. This is what the article should look like in landscape.
The problem has something to do with the UIWebView not autoresizing appropriately when it isn't currently visible. What can I do to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在 Interface Builder 中执行此操作。
单击 UIWebView 并按 Apple-3 调出“尺寸检查器”。
在“自动调整大小”下,确保选中框内的两个箭头。这将确保视图大小始终最大化到其容器。
You need to do this in Interface Builder.
Click on your UIWebView and press Apple-3 to pull up the "Size Inspector".
Under "Autosizing", make sure the two arrows inside the box are selected. This will make sure the view size is always maximized to its container.
您可以通过根据设备方向添加不同的 css 样式在服务器端更改它:
例如:
或者您可以从客户端更改视口:
如果您的页面有视口元标记:
那么在您的代码中,您可以在每次方向更改时更改此视口:
并在方向为纵向时再次更改
You can change it on server side by adding different css styles depending on device orientation:
for example:
or you could change viewport from client side:
In case your page has got viewport meta tag:
then in your code you can change this viewport every time orientation changes:
and change it again when orientation is portrait
备查。您可以使用此程序以编程方式执行此操作。
[webView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];
For future reference. You can do this programmatically with this.
[webView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];