I am working on a form that is running inside a webview. After one of the native ios popups comes up and closed, for example when keyboard appears in a text area, or when dropdown popups, there is a tap issue. There is an offset in the tapping that is approximately the height of the keyboard/dropdown popup. So when I tap a point on the form, a different component which is 200-300pixels down is pressed. It only occurs in ios12. The only workaround I found for that is pinch-out and in. Do you have any suggestions for a solution?
I fix it by a tricky method,You should try:
- (void)keybordDidHide {
if (!CGPointEqualToPoint(self.lastContentOffset, self.webView.scrollView.contentOffset)) {
[self.webView.scrollView setContentOffset:self.lastContentOffset];
[self.webView.scrollView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
}
- (void)keybordWillShow {
self.lastContentOffset = self.webView.scrollView.contentOffset;
}
This did work for me.
ViewController.h
@property (nonatomic) CGPoint lastContentOffset;
ViewController.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)];
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.