Overflowing drop down button in a tableview cell: can I make it clickable?

早过忘川 提交于 2021-02-11 15:46:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!