Giter Site home page Giter Site logo

Comments (3)

mohpor avatar mohpor commented on May 3, 2024 7

It's pretty straightforward:

  • You should be able to calculate the height (for opened state) for each cell individually.
  • then
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var duration = 0.0
    if cellHeights[indexPath.row] == kCloseCellHeight { // open cell
      cellHeights[indexPath.row] = openHeightForRow(at: indexPath) /*kOpenCellHeight*/ // This value must be more than twice the size of kCloseCellHeight otherwise asserts will break loose!
      cell.selectedAnimation(true, animated: true, completion: nil)
      duration = 0.5
    } else {// close cell
      cellHeights[indexPath.row] = kCloseCellHeight
      cell.selectedAnimation(false, animated: true, completion: nil)
      duration = 1.1
    }

    UIView.animateWithDuration(duration, delay: 0, options: .CurveEaseOut, animations: { () -> Void in
      tableView.beginUpdates()
      tableView.endUpdates()
      }, completion: nil)
  }
  • Don't forget to update your containerView's height (preferably in cellForRowAtIndexPath...) and if you want, you can even customize how many times your cell folds!:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    guard let cell = tableView.dequeueReusableCellWithIdentifier(cellID, forIndexPath: indexPath) as? FoldingCell else {
      return UITableViewCell()
    }

    let height = messageHeightForCell(at: indexPath)
    cell.containerHeightConstraint.constant = height
    cell.itemCount = Int(round(height / 100.0)) // Decides number of folds for cell
    return cell
  }
  • in case you have variable itemCounts (a.k.a. folds), in your cell:
override func animationDuration(itemIndex: NSInteger, type: AnimationType) -> NSTimeInterval {
    var durations = [0.26]
    for _ in 1...itemCount {
      durations.append(0.2)
    }
    return durations[itemIndex]
  }

well, I guess that's it!

from folding-cell.

volkermatthes avatar volkermatthes commented on May 3, 2024

I would be intrerested in a solution for this aswell 👍

from folding-cell.

FlyingAppleFish avatar FlyingAppleFish commented on May 3, 2024

nice

from folding-cell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.