问题
I am working on this project where I am using drop down menus in tableView cells. I am using the following code to make the drop down part overflow the tableView cells bottoms
cell.clipsToBounds=false
cell.contentView.clipsToBounds=false
Everything works fine, but when I scroll down the tableView till the drop down part is not visible anymore, the overflow stops working. You can see the problem in action in the project below
https://github.com/Rawchris/Drop-down-overflow2
In the project I have put drop down buttons in every cell, but it is fine if it is just the first one that is working. I hope you are able to help. Please tell me if you need anymore information.
回答1:
The problem is not that "overflow stops working" ... the problem is that table view cells are not drawn in order.
Taking the answer from your other question: https://stackoverflow.com/a/61252794/6257435
I shortened the cell heights to make it easier to see.
In this image:
I scrolled up and down a few times before tapping the "Row 8" button. As you can see, your gray "drop down" menu is hidden behind rows 9 and 10.
Using Debug View Hierarchy
you can see exactly what's going on:
You could get around this by using a closure or delegate protocol to tell your tableViewController to bring that cell to the front when the menu is opened, but... you may still run into issues when scrolling while a "drop down" is showing. You'll also hit problems when the "drop down" is showing for multiple rows at the same time.
In general, it's not a good idea to draw outside the bounds of other views. Many issues can arise. Also - of course, this may be considered just personal opinion - the whole "drop down selection list" feels very out-of-place on a phone or tablet. It makes for a rather clunky / awkward user experience. If I were you, I'd re-think my approach.
来源:https://stackoverflow.com/questions/61170547/swift-dropdown-overflow-disappears-when-scrolling-down