Within my swift app, I am trying to hide the inputAccessoryView that shows when a user taps a textfield inside of a webview.
Here is the code attempting to do that:
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
var keyboardView = UIApplication.sharedApplication().windows.last!.subviews.first!
keyboardView.inputAccessoryView = nil
}
}
But I am getting this error:
Cannot assign to property: ‘inputAccessoryView’ is a get-only property
Is there a better way to do this? Any ideas on how to get this to work?
I think the error is due to the way the keyboardView is declared.
When I create my own UIView and assign it as the inputView for a first responder, I can then assign (or set to nil) the first responder's inputAccessoryView.
I assume you are trying to remove an existing accessory view, as Apple says that the default value is nil. I found this workaround for iOS 7, maybe this still works? Somebody subclassed a UIWebDocumentView and then put in an implementation of inputAccessoryView that returns nil. It's in Obj-C, but it looks promising:
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.