表格视图单元格中的溢出下拉按钮:我可以让它可点击吗? [英] Overflowing drop down button in a tableview cell: can I make it clickable?
问题描述
我目前正在做一个项目,在该项目中我在 tableview 单元格中放置了一个下拉按钮.下拉部分"溢出单元格底部并进入下面的单元格.现在我无法点击溢出部分.有没有办法让这部分可点击?您可以在下面的链接中找到我的部分代码
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
为了说明清楚,我希望能够点击上面项目中的选项 3 和 4.如果你想让我进一步解释我的问题,请告诉我.
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.
推荐答案
所以问题是:您有一个超出其父视图的按钮,因此无法单击?是的,您可以使超级视图之外的部分可点击;您需要执行hit-test munging",覆盖 hitTest(_:with:)
以便按钮可以成为命中测试视图,即使它的一部分在其超级视图之外.您需要在按钮的超级视图中使用此代码(或类似代码):
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
}
这篇关于表格视图单元格中的溢出下拉按钮:我可以让它可点击吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!