显示键盘后 UIWebView 上的 scalesPageToFit 损坏了? [英] scalesPageToFit broken on UIWebView after keyboard is shown?

查看:27
本文介绍了显示键盘后 UIWebView 上的 scalesPageToFit 损坏了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个元标记:

<meta name="viewport" content="width=768, minimum-scale=1.0, user-scalable=no" />

我正在设置 scalesPageToFit:

And I am setting scalesPageToFit:

webView.scalesPageToFit = YES;

起初这可以正常工作.当我从纵向转到横向时,它会放大,因此设备的宽度始终为 768 像素.我可以毫无问题地来回走动(纵向 <-> 横向).

At first this works correctly. When I go from portrait to landscape it zooms in so the width of the device is always 768px. I can go back and forth with no issues (portrait <-> landscape).

一旦我激活虚拟键盘,无论是通过 contentEditable 还是文本区域,它都会完全停止工作,即使在我关闭键盘之后也是如此.

As soon as I activate the virtual keyboard, whether it be through a contentEditable or text area, it stops working completely, even after I dismiss the keyboard.

这是 UIWebView 中的错误吗?我还需要做些什么来完成这项工作吗?有我可以使用的解决方法吗?无论方向如何,宽度都必须为 768 像素.

Is this a bug in the UIWebView? Is there anything else I need to do to make this work? Is there a work-around I can use? The width, no matter the orientation, has to be 768px.

推荐答案

似乎是苹果私有类 UIDocumentView 的一个 bug.无论出于何种原因,viewportConfigurationsDidChange 在键盘激活后都会卡在缩放比例上,这是通过调用 _setDocumentScale 设置的.例如,当它应该更改为 1.333 时,它会卡在 1.0 上.

Seems to be a bug with Apple's private class UIDocumentView. For what ever reason viewportConfigurationsDidChange gets stuck on a zoom scale after the keyboard is activated, which is set by calling _setDocumentScale. When it's supposed to change to 1.333, for example, it gets stuck on 1.0.

通过为 UIWebDocumentView 编写一个类别是可修复的",UIWebDocumentView 是 UIDocumentView 的子类,没有实现这些方法(因此您可以调用超级类).

It's "fixable" by writing a category for UIWebDocumentView, which is a subclass of UIDocumentView that doesn't implement these methods (so you can call the super's).

尽管我尽了最大努力,但我还是找不到使用公共 API 解决此问题的方法.我尝试弄乱 UIScrollView 的缩放级别,但我永远无法让它正常工作.内容会发生变化,并且会发生其他奇怪的事情.甚至尝试用 JavaScript 来实现.

Despite my best efforts I couldn't find a way to fix this using the public API. I tried messing with the UIScrollView's zoom level, but I could never get that to work correctly. The content would get shifted, and other weird things would happen. Even tried doing it with JavaScript.

所以解决它的唯一方法是通过私有类的类别.

So the only way to fix it is through category on private classes.

这在应用商店中永远不会被批准.

所以,在 Apple 修复此问题之前,SOL.

So until Apple fixes this, SOL.

这篇关于显示键盘后 UIWebView 上的 scalesPageToFit 损坏了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆