У меня есть проблема, из-за которой WkWebView не поднимается при появлении клавиатуры.
Я хочу, чтобы мой WKWebView заблокировал положение.
Есть идеи исправить мой код?
Или любой код JavaScript может достичь этого.
Спасибо.
@property (strong, nonatomic) IBOutlet WKWebView *webView;
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardShow:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
CGRect keyboardRect = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGFloat keyboardHeight = UIInterfaceOrientationIsPortrait(self.interfaceOrientation)?keyboardRect.size.height:keyboardRect.size.width;
CGFloat duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
CGFloat animationStyle = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] floatValue];
self.offset = self.webView.scrollView.contentOffset;
UIEdgeInsets contentInsets = self.webView.scrollView.contentInset;
contentInsets.bottom = keyboardHeight;
[UIView animateWithDuration:duration delay:0 options:animationStyle animations:^{
self.webView.scrollView.contentInset = contentInsets;
} completion:nil];
}
- (void)keyboardHide:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
CGFloat duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
CGFloat animationStyle = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] floatValue];
UIEdgeInsets contentInsets = self.webView.scrollView.contentInset;
contentInsets.bottom = 0;
[UIView animateWithDuration:duration delay:0 options:animationStyle animations:^{
self.webView.scrollView.contentInset = contentInsets;
self.webView.scrollView.contentOffset = self.offset;
} completion:nil];
}