iOS UIWebview 自动调整大小/缩放

发布于 2024-10-20 11:06:45 字数 501 浏览 6 评论 0原文

我正在尝试重新设计应用程序的方向处理功能,但遇到了一些麻烦。我有一个 UIWebview,它是唯一始终可见的视图。 UIWebview 呈现自定义 HTML 页面,这些页面始终具有固定的正文大小,与设备的屏幕分辨率相匹配。例如,iPad 纵向页面的主体尺寸可能为 768x1024,横向页面的尺寸为 1024x768。当设备以纵向方向握持并显示纵向页面时,UIWebview 应以全屏分辨率显示页面。当设备横向放置并显示纵向页面时,我希望 UIWebview 自动缩放以垂直适应屏幕,并水平居中。反之亦然,横向页面同时保持纵向。基本上,我希望显示的页面始终具有正确的宽高比,无论大小如何,同时位于屏幕中央。

我确信 IB 中的自动调整大小设置的某些组合可以实现此目的,但我似乎找不到正确的设置。我有一个主要工作的解决方案,可以在页面加载或方向更改后手动调整 UIWebView 框架的大小和位置,但它偶尔会出现问题并且无法正确显示。使用视图本身的自动大小/缩放属性似乎应该可以实现这一点。 任何帮助将不胜感激。 提前致谢

I'm attempting to re-work the orientation handling functionality of an app, having a bit of trouble. I have a UIWebview that is the only view visible at all times. The UIWebview renders custom HTML pages that will always have fixed body size, matched to the screen resolution of the device. So for example, there might be an iPad portrait page with body size 768x1024, and a landscape page would be 1024x768. When the device is being held in Portrait orientation, and displaying a portrait page, the UIWebview should display the page at full screen resolution. When the device is being held in landscape orientation and displaying a portrait page, I would like the UIWebview to automatically scale to fit the screen vertically, and be centered horizontally. Vice versa with landscape pages while being held in portrait orientation. Basically, I want the page being displayed to always have the correct aspect ratio, regardless of size, while being centered in the screen.

I am sure there is some combination of the autosize settings in IB that will accomplish this, but I cannot seem to find the right setup. I have a mostly working solution that manually resizes and positions the UIWebView frame after a page load or orientation change, but it occasionally acts up and doesn't display properly. It seems like this ought to be possible using the auto size/scale properties of the view itself.
Any help would be greatly appreciated.
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文