Это сработало для меня.
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)];
}
}