2015-07-19 98 views
0

我试图在点击时从行下滑出一个抽屉。我已经掌握了所有的工作,但我无法获得zposition集。我尝试了几种不同的方式,但它不适合我。我可以将视图与行的底部对齐,但动画仍然在栈顶上发生。zposition for UITableViewCell(swift)

我敢肯定我错过了一些明显的东西。这甚至有可能吗?

我的代码是在这里:https://gist.github.com/opswhisperer/14d8dbfb9f16dab8e1a8

(GIST与thattyson的答案更新)

screenshot

+0

而不是添加一个新的视图,你可以动画单元格的高度来揭示更多?类似于[这个问题](http://stackoverflow.com/questions/460014/can-you-animate-a-height-change-on-a-uitableviewcell-when-selected) – thattyson

+0

我可以(而且我做到了)但这不是我在 – rjb101

回答

1

幸运的,它看起来像UITableView中所选择的小区中移动到堆栈的顶部(z-index的)当你选择它,所以你只需要一个参考单元格:

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 
} 

你的看法应该出现beh ind选中的单元格。

+0

后的效果是!谢谢。我也必须删除所有我尝试过的zposition。 – rjb101