我现在正试着将
this转换成Swift而没有真正的背景.
这是我到目前为止所得到的…而且我一直在寻找谷歌并不知道要搜索什么才能更具体.你能否详细说明我做错了什么?谢谢
更新:
我已经找到了objective-c标签,因此更多与此线程相关的人可能能够看到它并希望得到答案.
解决方法
Michael Dautermann回答说得对,但是为了隐藏附件栏,你需要使用_NoInputAccessoryView类的inputAccessoryView()来调用UIView类的方法inputAccessoryView().我刚刚在代码中添加了几行额外的行来完成这个方法调配工作.
首先,你需要一个假类来交换
final class FauxBarHelper: NSObject { var inputAccessoryView: AnyObject? { return nil } }
然后在控制器类中创建此方法
/// Removes the keyboard accessory view from the web view /// Source: https://stackoverflow.com/a/32620344/308315 / https://stackoverflow.com/a/33939584/308315 func _removeInputAccessoryView(webView: UIWebView) { var targetView: UIView? = nil for view in webView.scrollView.subviews { if String(describing: type(of: view)).hasPrefix("WKContent") { targetView = view } } guard let target = targetView else { return } let noInputAccessoryViewClassName = "\(target.superclass!)_NoInputAccessoryView" var newClass: AnyClass? = NSClassFromString(noInputAccessoryViewClassName) if newClass == nil { let targetClass: AnyClass = object_getClass(target) newClass = objc_allocateClassPair(targetClass,noInputAccessoryViewClassName.cString(using: String.Encoding.ascii)!,0) } let originalMethod = class_getInstanceMethod(FauxBarHelper.self,#selector(getter: FauxBarHelper.inputAccessoryView)) class_addMethod(newClass!.self,#selector(getter: FauxBarHelper.inputAccessoryView),method_getImplementation(originalMethod),method_getTypeEncoding(originalMethod)) object_setClass(target,newClass) }
HTH;)