gpt4 book ai didi

ipad - 可编辑的 webView 自行滚动到顶部

转载 作者:行者123 更新时间:2023-12-01 06:50:36 25 4
gpt4 key购买 nike

我在可编辑的 web View 中显示了一些文本。一旦我向下滚动并触摸某处以编辑呈现的文本,它就会滚动到顶部并出现键盘,因此我必须再次向下滚动以进行编辑。有没有办法阻止 webView 这样做?

最佳答案

遇到同样的问题,仍在寻找这种奇怪行为的正常解决方案。我们仍然无法阻止 UIWebView 这样做,如果你在 iPad 上查看 Evernote 应用程序,你会在那里看到同样的问题,不幸的是:(我们唯一能做的就是在显示键盘时保存 UIWebView 的 contentOffset 并在打开键盘后恢复。

这看起来像:

//register your controller for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) UIKeyboardDidShowNotification object:nil];

然后您将需要处理键盘通知,例如:

- (void)keyboardWillShow:(NSNotification *)aNotification {

// scroll view will scroll to beginning, but we save current offset
[_yourViewWithWebView saveOffset];
...
}

之后,您需要在显示键盘时处理事件:

- (void)keyboardWasShown:(NSNotification*)aNotification{
...
// scroll view scrolled to beginning, but we restore previous offset
[_yourViewWithWebView restoreOffset];
}

因此,在您需要实现的包含 UIWebView 的 View 中:

static CGPoint editableWebViewOffsetPoint;

- (void) saveOffset{
editableWebViewOffsetPoint = yourWebView.scrollView.contentOffset;
}

- (void) restoreOffset{
//just use animation block to have scroll animated after jumping to top and back to old position
[UIView animateWithDuration:.2
delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
yourWebView.scrollView.contentOffset = editableWebViewOffsetPoint;
}
completion:nil];

}

总体而言,希望这将帮助您至少部分解决您的问题。

如果有人能帮助我们防止每次显示键盘时 UIWebView 滚动到顶部,我将不胜感激。

UIWebView.scrollView.scrollsToTop = NO; 没有帮助。

在显示键盘之前禁用滚动并在显示键盘后启用它也不起作用。

此外,当光标不在 UIWebView 的可见区域时,您将面临编辑文本的问题 - 它不会自动滚动以使光标可见。我们已经解决了这个问题,但我正在创建详细且易读的教程,说明我们如何做到这一点。如果您已经解决了这个问题,我会很高兴看到您的解决方案:)

PS:http://www.cocoanetics.com/2011/01/uiwebview-must-die/

谢谢你,谢尔盖 N.

关于ipad - 可编辑的 webView 自行滚动到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11520184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com