[英]Cannot assign to property: ‘inputAccessoryView’ is a get-only property
Within my swift app, I am trying to hide the inputAccessoryView that shows when a user taps a textfield inside of a webview. 在我的swift应用程序中,我试图隐藏inputAccessoryView,该视图显示用户点击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. 我认为错误是由于keyboardView的声明方式。
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. 当我创建自己的UIView并将其指定为第一响应者的inputView时,我可以将第一个响应者的inputAccessoryView分配(或设置为nil)。
I assume you are trying to remove an existing accessory view, as Apple says that the default value is nil. 我假设您正在尝试删除现有的附件视图,因为Apple说默认值为nil。 I found this workaround for iOS 7, maybe this still works?
我找到了适用于iOS 7的解决方法,也许这仍然有效? Somebody subclassed a UIWebDocumentView and then put in an implementation of inputAccessoryView that returns nil.
有人将UIWebDocumentView子类化,然后放入一个返回nil的inputAccessoryView实现。 It's in Obj-C, but it looks promising:
它在Obj-C中,但看起来很有希望:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.