问题
I am currently working on a project where I am placing a drop down button inside a tableview cell. The "drop down part" overflows the bottom of the cell and goes into the cell below. Right now I am are not able to click the overflowing part. Are there a way to make this part clickable? You can find a part of my code in the link below
https://github.com/Rawchris/Drop-down-overflow
To spell it out, I would like to be able to click Option 3 and 4 in the project above. Please tell me if you want me to explain my question further.
回答1:
So the question is: you've got a button that goes outside of its superview and therefore cannot be clicked? Yes, you can make the part outside the superview clickable; you'd need to perform "hit-test munging", overriding hitTest(_:with:)
so that the button can be the hit-test view even when part of it is outside its superview. You would need this code (or similar) in the button's superview:
override func hitTest(_ point: CGPoint, with e: UIEvent?) -> UIView? {
if let result = super.hitTest(point, with:e) {
return result
}
for sub in self.subviews.reversed() {
let pt = self.convert(point, to:sub)
if let result = sub.hitTest(pt, with:e) {
return result
}
}
return nil
}
来源:https://stackoverflow.com/questions/61078887/overflowing-drop-down-button-in-a-tableview-cell-can-i-make-it-clickable