Setup
I implemented an inputAcessoryView
in a UIViewController
via the following:
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
implements an action on .touchUpInside
.
The issue
The button is only clickable in the part included in inputAccessoryView
's frame: if I click on it on the part that's outside, nothing happens.
Is there any quick way to make it work like so ?
I have tried moving the photoButton
out of bottomBarView
and adding it to the view instead however:
- I need
photoButton
to be "anchored" to theinputAccessoryView
, but it seemsinputAccessoryView
doesn't have anchor properties from within the view ? (I can only access theirframe
properties via bang unwrapping) - When I do so,
photoButton
is partly hidden behindinputAccessoryView
and I can't bring it forward withview.bringSubview(ToFront:)
Thanks in advance.