I have a strange problem. The keyboard works when I have the app connected to Xcode. If app turn off and on again, the keyboard with UITextView and UITextField no longer works... but UISearchField works.
I use this methods:
- (void)addKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(questionCellTextViewBeginEditing:) name:@"QuestionCellTextViewBeginEditingNotification" object:nil];
}
For example keyboardWillShow in Objective-C look like:
- (void)keyboardWillShow:(NSNotification *)notification {
[_tableView setContentBottomInset:[Tools keyboardHeightFromNotification:notification]];
[self.view layoutIfNeeded];
[UIView animateWithDuration:0.3f animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
[_tableView scrollToRowAtIndexPath:selectedIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}];
}
And I use Swift version in a few places in app:
@objc func keyboardWillShow(sender: Notification) {
keyboardHeight = (sender.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect).size.height
if #available(iOS 11.0, *) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
if (appDelegate.window?.safeAreaInsets.top)! > CGFloat(0.0) || appDelegate.window?.safeAreaInsets != .zero {
keyboardHeight -= (appDelegate.window?.safeAreaInsets.bottom)!
}
}
let y = self.tableView.contentOffset.y + keyboardHeight
self.tableView.contentOffset = CGPoint.init(x: 0, y: y)
self.textViewContainerBottomConstraint?.constant = keyboardHeight
self.view?.layoutIfNeeded()
UIView.animate(withDuration: 0.3) {
self.view?.layoutIfNeeded()
}
}
I am wondering about this log printed in console when I terminated app:
[27682:19912067] [Snapshotting] Snapshotting a view (0x7fa4e304d400, UIKeyboardImpl) that is not in a visible window requires afterScreenUpdates:YES.
Do you know where is problem? I have no idea how to test an application without being debugged in Xcode.