【问题标题】:iphone: reloading webview with rotationiphone:使用旋转重新加载webview
【发布时间】:2026-02-02 11:40:01
【问题描述】:

我正在使用 uiwebview 来显示一个非常基本的仅包含文本的 html 页面。我想支持横向和纵向方向,但是当方向改变时我在调整大小时遇到​​了问题。具体来说,当 iphone 旋转到横向时,它会放大文本(我希望文本大小保持不变并填充更宽的水平空间)。当它旋转回纵向时,文本会恢复到正确的大小,但现在它会从页面向右流动。

我认为解决方案是在每次更改方向时重新加载页面。有没有办法在每次旋转 iphone 时重新加载页面?

【问题讨论】:

    标签: iphone webview orientation rotation


    【解决方案1】:

    当视图控制器接收到以下任一方法时,您可以在 Web 视图上调用 reload

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
    

    您可以尝试在网络视图中设置scalesPageToFit=NO。您可以从 html 对 webview 进行相当精细的控制。查看viewport 和其他可以使用的元标记。

    【讨论】: