Ios 平滑的UITableView单元扩展,具有手风琴风格

Ios 平滑的UITableView单元扩展,具有手风琴风格,ios,swift,uitableview,Ios,Swift,Uitableview,“我的表格视图”可以在按下单元格时展开和折叠单元格,但在动画完成之前会加载单元格展开时显示的内容 留给我的是: 我希望它看起来像什么。该内容看起来就像是在一个帘子后面,单元扩展动画正好显示了它 以下是控制表视图的代码: class HistoryViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{ var expandedIndexPath: NSIndexPath? // Inde

“我的表格视图”可以在按下单元格时展开和折叠单元格,但在动画完成之前会加载单元格展开时显示的内容

留给我的是:

我希望它看起来像什么。该内容看起来就像是在一个帘子后面,单元扩展动画正好显示了它

以下是控制表视图的代码:

class HistoryViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{

    var expandedIndexPath: NSIndexPath? // Index path of the cell that is currently expanded
    let collapsedHeight: CGFloat = 44.0 // Constant to set the default collapsed height
    var ticketHistoryService = TicketHistoryService() // Service to gather info about Ticket History CoreData

    var tickets = [Ticket]()

    @IBOutlet var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Remove any appended table view cells
        tableView.tableFooterView = UIView()

        self.tickets = self.ticketHistoryService.fetchData() // Load inital data

    }

    // MARK: - Table View Methods

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.tickets.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! HistoryTableViewCell

        let ticket = self.tickets[indexPath.row]

        cell.titleLabel!.text = ticket.ticketNumber
        return cell
    }

    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            self.ticketHistoryService.removeObject(indexPath.row)
            self.tickets = self.ticketHistoryService.fetchData()
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        }
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        self.tableView.beginUpdates()
        let cell = self.tableView.cellForRowAtIndexPath(indexPath) as! HistoryTableViewCell
        if indexPath.isEqual(self.expandedIndexPath){ // If currently selected cell was just previously selected
            self.expandedIndexPath = nil
            cell.commentLabel.hidden = true
        }
        else {
            self.expandedIndexPath = indexPath
            cell.commentLabel.hidden = false
        }
        self.tableView.endUpdates()
    }

    func tableView(tableView: UITableView, willDeselectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
        let cell = self.tableView.cellForRowAtIndexPath(indexPath) as! HistoryTableViewCell
        cell.commentLabel.hidden = true
        return indexPath
    }

    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        if indexPath.isEqual(self.expandedIndexPath) {
            return UITableViewAutomaticDimension
        }
        return collapsedHeight
    }
}

一种方法是将单元格剪辑子视图内容扩展到其自身之外:

let cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! HistoryTableViewCell
cell.clipsToBounds = true

使用这行代码cell.contentView.clipstobunds=YES;谢谢你的回答。有点离题,但我应该什么时候隐藏内容?在折叠动画完成之前,其他单元格内容将消失。我能让内容消失,就像它出现一样吗?“DrWANTANN,您可以考虑不隐藏它,因为它不会出现在<代码> clipStopBoos<代码>启用的情况下。或者,您可以在
UIView
动画块内将其
alpha
设置为
0