Why in iOS14 (or at least iOS14.4.1 iPhone X) keyboardWillShowNotification is fired when background(UIScrollerView) taped, while in iOS13 is not?
I am trying to run a function when the keyboard shows and disappears, have the following code:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var textField: UITextField!
let notificationCenter = NotificationCenter.default
override func viewDidLoad() {
super.viewDidLoad()
notificationCenter.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
notificationCenter.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
}
deinit {
notificationCenter.removeObserver(self)
}
@objc private func keyboardWillShow(_ notification: Notification) { updateBottomLayoutConstraintWithNotification(notification: notification, bottomConstraint: nil, tag: "keyboardWillShow()")
}
@objc private func keyboardWillHide(_ notification: Notification) { updateBottomLayoutConstraintWithNotification(notification: notification, bottomConstraint: nil, tag: "keyboardWillHide()")
}
func updateBottomLayoutConstraintWithNotification(notification: Notification, bottomConstraint: NSLayoutConstraint?, tag: String = "") {
print("[Caller Name] \(tag)")
}
}
Operation steps
Tap the textField(Keyboard Raised)
Tap the background(UIScrollerView)
Such a log will be generated
[Caller Name] keyboardWillShow()
[Caller Name] keyboardWillShow()
Thank you for your attention!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Widgets are activated by the iOS system at regular intervals, and the task code defined in the TimelineProvider is executed.
How long can this task code be executed at most?
I don't think the system will allow tasks defined in the timeline to be executed continuously (looking like a background resident program), so there must be a time limit.
If you know, or if there are related document links, please let me know
Thank you.