How can I use CCClippingNode to trim the top and bottom from a CCTableView?

| | August 4, 2015

I’m fairly new to Cocos2d and struggling with sizing a CCTableView. How can its height be controlled so that I have space at the top and the bottom?

I’m trying to visually wrap the top and bottom of my table view with a sprite, to provide the look and feel of a frame. But when I touch the table view, to scroll it up or down, it occupies most of the screen vertically. I thought the contentSize would alter where each cell appears and disappears from the top and bottom, but changing it had no effect.

Having had a Google about, I’m reading that I have to use a Clipping Node with a Stencil? Coming from UIkit, this seems like a bit of a faff. Would anyone like to hazard at a tutorial, bit of code with a simple CCTableView representation, sat in the middle of the scene where each cell appears and disappears under a content frame?

One Response to “How can I use CCClippingNode to trim the top and bottom from a CCTableView?”

  1. I ended up altering the contentSize of the CCTableView.

    So,

    someTableView.contentSize = CGSizeMake(200, 300); 
    

    …and then I placed a CCSprite over it with a hole in the middle that had transparency. This way, the table view was clipped how I wanted it clipped. I added the tableView to my scene with a lower z-order than that of the sprite. Did not need the complexity of what I was describing above.

Leave a Reply