开发者

Using a CALayer in UITableViewCell

On each cell of my table view I want to have a bar that the user can slide out from the right. On the bar I plan to have icons. So, to do this I subclassed UITableViewCell. On the cell I have implemented drawRect and in there I have already drawn a gradient and background color on the cell. From there, I can create a CALayer, give it a frame & background color, and add it as a sub layer to the Views subLayers array. I can do all that and it will display my layer on each UITableViewCell.

I have added touch events to the cell so I can detect when the user touches the cell and for testing I have made it so when the user swipes, my CALayer gets wider. But the issue is, when the UITableView scrolls and reuses a cell whose CALayer has been widened, it doesn't recreate the CALayer. I have tried

开发者_StackOverflow
[myLayer setNeedsDisplay]

and used the drawLayer:inContext method of its delegate and it doesn't get called. I have also tried telling call setNeedsDisplay on the cell in my UITableViewController hoping that that will cause a redraw, but it doesn't work.

I'm not sure what I'm missing. I am new to CoreGraphics & CoreAnimation. I have read through the CoreAnimation Developers Guide, but I'm assuming I missing something. Any help would be great.


I added a closed transform and open transform to the CALayer. In the table view controller's scrollViewWillBeginDragging, I iterate over all the visible cells and call apply my closed transform to reset the menu.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜