ios - ios12中的点击偏移问题
问题描述
我正在处理在 webview 中运行的表单。在本机 ios 弹出窗口之一出现并关闭后,例如当键盘出现在文本区域中或下拉弹出窗口时,会出现点击问题。敲击中有一个偏移量,大约是键盘/下拉弹出窗口的高度。因此,当我点击表单上的一个点时,会按下一个向下 200-300 像素的不同组件。它只出现在 ios12 中。我找到的唯一解决方法是夹出和夹入。您对解决方案有什么建议吗?
解决方案
这确实对我有用。
视图控制器.h
@property (nonatomic) CGPoint lastContentOffset;
视图控制器.m
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onKeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
- (void)onKeyboardWillShow:(NSNotification *)notification {
self.lastContentOffset = self.webView.scrollView.contentOffset;
}
- (void)onKeyboardWillHide:(NSNotification *)notification {
if (!CGPointEqualToPoint(self.lastContentOffset, self.webView.scrollView.contentOffset)) {
[self.webView.scrollView setContentOffset:self.lastContentOffset];
[self.webView.scrollView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
if (!CGPointEqualToPoint(self.lastContentOffset, self.webView.scrollView.contentOffset)) {
[self.webView.scrollView setContentOffset:self.lastContentOffset];
[self.webView.scrollView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
}
推荐阅读
- javascript - 赛普拉斯包含 if/else 条件中的语句
- javascript - 非法的字符串偏移并且未在 contact-script.php 中显示表单字段
- javascript - 如何从 JavaScript 中的本地目录检索文件名?
- google-chrome-devtools - 无法从开发工具中获取颜色十六进制值
- c# - Microsoft Identity Web:更改重定向 Uri
- python - Jupyter Notebook 在 vpython 中不显示任何输出,并且在重新启动内核后仅显示一次输出,而不是再次显示
- http - 如何在终端中使用命令行将我的 https 更改为 http?
- java - 如果我的验证器需要在验证之前调用数据库,我应该让数据库处理这个验证吗?
- postgresql - 如何解决 Scala 中的 GC 超限问题?
- kubernetes - io.fabric8.kubernetes.client.KubernetesClientException:禁止!配置的服务帐户无权访问