0

I'm trying to make a drawer that slides out from under the row when it is clicked. I've got it all working except that I can't get the zposition set. I've tried several different ways but its not working for me. I could line the view up with the bottom of the row but the animation still happens on top of the stack.

I'm sure I'm missing something obvious. Is this even possible?

My code is here: https://gist.github.com/opswhisperer/14d8dbfb9f16dab8e1a8

(gist updated with thattyson's answer)

screenshot

rjb101
  • 514
  • 5
  • 14
  • Instead of adding a new view, could you just animate the height of the cell to reveal more? Similar to [this question](http://stackoverflow.com/questions/460014/can-you-animate-a-height-change-on-a-uitableviewcell-when-selected) – thattyson Jul 19 '15 at 05:39
  • I could (and I did) but that's not the effect I'm after – rjb101 Jul 19 '15 at 05:40

1 Answers1

1

Fortunately it looks like UITableView moves the selected cell to the top of the stack (z-index) when you select it so you just need a reference to the cell:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true)

    let drawerView = UIView(frame: CGRectMake(0, 50, 200, 200))
    drawerView.backgroundColor = UIColor.purpleColor()
    // TODO: set the frame based on the location of the selectedCell

    let selectedCell = tableView.cellForRowAtIndexPath(indexPath)
    selectedCell?.superview?.insertSubview(drawerView, belowSubview: selectedCell!)

    // TODO: Add super slick animation
}

Your view should appear behind the selected cell.

thattyson
  • 718
  • 8
  • 17