设置
我通过以下方式实现了inputAcessoryView
一个:UIViewController
override var inputAccessoryView: UIView? {
get {
return bottomBarView
}
}
override var canBecomeFirstResponder: Bool {
return true
}
fileprivate lazy var bottomBarView: UIView = {
let view = UIView()
let separatorLineView = UIView()
view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height / 9)
view.backgroundColor = .white
/...
separatorLineView.backgroundColor = UIColor(r: 220, g: 220, b: 220, a: 1)
separatorLineView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(separatorLineView)
separatorLineView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
separatorLineView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
separatorLineView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
separatorLineView.heightAnchor.constraint(equalToConstant: 1).isActive = true
view.addSubview(self.photoButton)
self.photoButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
self.photoButton.centerYAnchor.constraint(equalTo: separatorLineView.centerYAnchor, constant: -12).isActive = true
self.photoButton.widthAnchor.constraint(equalToConstant: view.frame.width / 4.5).isActive = true
self.photoButton.heightAnchor.constraint(equalToConstant: view.frame.width / 4.5).isActive = true
return view
}()
photoButton
对 执行操作.touchUpInside
。
问题
该按钮只能在包含在inputAccessoryView
框架中的部分中单击:如果我在外面的部分上单击它,则不会发生任何事情。
有什么快速的方法让它像这样工作吗?
但是,我尝试将其photoButton
移出bottomBarView
并将其添加到视图中:
- 我需要
photoButton
被“锚定”到inputAccessoryView
,但似乎inputAccessoryView
在视图中没有锚属性?(我只能frame
通过 bang unwrapping 访问它们的属性) - 当我这样做时,
photoButton
部分隐藏在后面inputAccessoryView
,我无法将其带入view.bringSubview(ToFront:)
提前致谢。