简体   繁体   中英

Solid example of expanding / accordion table view cell with background image needed

After reading numerous posts on SO and other sites, I still cannot seem to get a custom cell working that expands and retracts while animating the size change.

Accordion table cell - How to dynamically expand/contract uitableviewcell? is one of the posts that has the most promise, but I suspect it only works when using labels and not necessarily a background image. Many other sites also follow this same concept.

Here's what I've done:

I've tried adding one large (expanded) image to a cell's contentView, then adjusting it's size in layoutSubviews, but the change is instant so there is no animation.

I've tried adding two images (collapsed & expanded) to the cell's contentView, then setting them to hidden and visible as appropriate when setSelected:animated: is called, but the expanded cells can be clearly seen over the other cells when animating.

I've also tried setting the contentView of the cells clipTobounds to YES, but it doesn't appear to do anything.

After spending nearly 3 days on this, I'm tempted to sublass UIScrollView and make my own table view, or maybe make 2 versions of each cell, but I'm hoping it won't have to go that far.

Can anyone post a FULL example of a UITableViewCell subclass that can expand and collapse, with a background image, that animates and doesn't overlap the other cells?

Turns out using clipToBounds was the right way after all. Instead of doing it in the init method, it needs to be set in layoutSubviews.

Then, dynamically change the cell's view's frames to match the height of the cell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM