📃 FoldingCell is an expanding content cell with animation made by @Ramotion

Overview

FOLDING CELL

Expanding content cell with animation inspired by folding paper card material design.


We specialize in the designing and coding of custom UI for Mobile Apps and Websites.

Stay tuned for the latest updates:


CocoaPods CocoaPods Twitter Travis codebeat badge Carthage compatible Swift 4.0 Analytics Donate

Requirements

  • iOS 8.0+
  • Xcode 10.2

Installation

Just add the FoldingCell.swift file to your project.

or use CocoaPods with Podfile:

pod 'FoldingCell'

or Carthage users can simply add Mantle to their Cartfile:

github "Ramotion/folding-cell"

or Swift Package Manager by adding:

dependencies: [
.package(url: "https://github.com/Ramotion/folding-cell.git", from: "5.0.2")
]

to Package.swift

or just drag and drop FoldingCell.swift file to your project

Solution

Solution

Usage

  1. Create a new cell inheriting from FoldingCell

  2. Add a UIView to your cell in your storyboard or nib file, inheriting from RotatedView. Connect the outlet from this view to the cell property foregroundView. Add constraints from this view to the superview, as in this picture:

1.1

(constants of constraints may be different). Connect the outlet from this top constraint to the cell property foregroundViewTop . (This view will be shown when the cell is in its normal state).

  1. Add other UIViews to your cell, connect the outlet from this view to the cell property containerView. Add constraints from this view to the superview like in the picture:

1.2

(constants of constraints may be different). Connect the outlet from this top constraint to the cell property containerViewTop. (This view will be shown when the cell is opened)

Your result should be something like this picture:

1.3

  1. Set @IBInspectable var itemCount: NSInteger property is a count of folding (it IBInspectable you can set in storyboard). range 2 or greater. Default value is 2

Ok, we've finished configuring the cell.

  1. Adding code to your UITableViewController

5.1) Add constants:

fileprivate struct C {
  struct CellHeight {
    static let close: CGFloat = *** // equal or greater foregroundView height
    static let open: CGFloat = *** // equal or greater containerView height
  }
}

5.2) Add property for calculate cells height

     var cellHeights = (0..<CELLCOUNT).map { _ in C.CellHeight.close }

5.3) Override method:

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return cellHeights[indexPath.row]
    }

5.4) Added code to method:

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        guard case let cell as FoldingCell = tableView.cellForRowAtIndexPath(indexPath) else {
          return
        }

        var duration = 0.0
        if cellIsCollapsed {
            cellHeights[indexPath.row] = Const.openCellHeight
            cell.unfold(true, animated: true, completion: nil)
            duration = 0.5
        } else {
            cellHeights[indexPath.row] = Const.closeCellHeight
            cell.unfold(false, animated: true, completion: nil)
            duration = 0.8
        }

        UIView.animateWithDuration(duration, delay: 0, options: .CurveEaseOut, animations: { _ in
            tableView.beginUpdates()
            tableView.endUpdates()
        }, completion: nil)
    }

5.5) Control if the cell is open or closed

  override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

        if case let cell as FoldingCell = cell {
            if cellHeights![indexPath.row] == C.cellHeights.close {
                foldingCell.selectedAnimation(false, animated: false, completion:nil)
            } else {
                foldingCell.selectedAnimation(true, animated: false, completion: nil)
            }
        }
    }
  1. Add this code to your new cell class
    override func animationDuration(itemIndex:NSInteger, type:AnimationType)-> NSTimeInterval {

        // durations count equal it itemCount
        let durations = [0.33, 0.26, 0.26] // timing animation for each view
        return durations[itemIndex]
    }

if don't use storyboard and xib files

Create foregroundView and containerView from code (steps 2 - 3) look example: Folding-cell-programmatically

🗂 Check this library on other language:

📄 License

Folding cell is released under the MIT license. See LICENSE for details.

This library is a part of a selection of our best UI open-source projects.

If you use the open-source library in your project, please make sure to credit and backlink to https://www.ramotion.com/

📱 Get the Showroom App for iOS to give it a try

Try this UI component and more like this in our iOS app. Contact us if interested.

Comments
  • ContainerView Height Crash.

    ContainerView Height Crash.

    A lot of others mentioned this previously before but I'm also getting the same error. Why is this happening? The answer to this question should be clearly specified in the doc. Everything needs to be significantly clearer.

    opened by HackShitUp 12
  • Cells Not Appearing - Swift 3/Xcode 8

    Cells Not Appearing - Swift 3/Xcode 8

    There was a discussing about the cells not appearing on another thread regarding swift 3 (linked below). I wanted to post it as another issue so in the future other developers have a solution.

    If anybody knows the downsides of saving the storyboard for xcode 7.x, I would love to understand those so we aren't impacted by them in the future.

    I also wanted to check if this would have any impact on submission to the app store or the use of new features in xcode 8.

    If anybody else has any solutions that do not require us to save the storyboard for 7.x, please let us know!

    Has anybody opened a radar for this issue?

    https://github.com/Ramotion/folding-cell/issues/65

    opened by nevinjethmalani 8
  • fatalError(

    fatalError("set foregroundViewTop or containerViewTop outlets in storyboard")

    Hi, please let me ask about the title issue that I encountered.

    I tried to setup Folding-cell, reading Readme. However, I came across this fatalError due to something wrong. I'm going to show how I did so that could you tell me what was wrong?

    Swift5.2

    1

    Added RotatedView inherited from RotatedView in new cell, like below.

    Screen Shot 2020-04-21 at 6 08 31

    2

    Set Top Constraint between RotatedView-top from SuperView (Cell Top). And added identifier to this constraint as "foregroundViewTop" like below.

    Screen Shot 2020-04-21 at 6 10 24

    3

    Connect IBOutlets from Open Folding Class to RotatedView and foregroundViewTop constraint.

    Screen Shot 2020-04-21 at 6 12 22

    4

    Added ContainerView inherited from FoldingCell in order to use itemCount. (I have set 2 folding view so that I have set 2 items here)

    Screen Shot 2020-04-21 at 6 18 14

    5

    Set Top Constraint between ContainerView-top from SuperView (Cell Top). And added identifier to this constraint as "containerViewTop" like below.

    Screen Shot 2020-04-21 at 6 15 07

    6

    Connect IBOutlets from Open Folding Class to ContainerView and containerViewViewTop constraint.

    Screen Shot 2020-04-21 at 6 16 42

    After above, I have added code written on README like below.

    fileprivate struct C {
      struct CellHeight {
        static let close: CGFloat = 67.0
        static let open: CGFloat = 138.0
      }
    }
    
    final class SongsViewController: UIViewController {
    
        /// Propaties
        var cellHeights = (0..<2).map { _ in C.CellHeight.close }
        
        override func viewDidLoad() {
            super.viewDidLoad()
    
            initViews()
        }
    
    extension SongsViewController: UITableViewDataSource {
    
        func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
            return cellHeights![indexPath.row]
        }
    
        func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
            return cellHeights[indexPath.row]
        }
    
        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            guard case let cell as FoldingCell = tableView.cellForRow(at: indexPath) else {
              return
            }
    
            var duration = 0.0
            if cellIsCollapsed { // this is not found.
                cellHeights[indexPath.row] = C.CellHeight.open
                cell.unfold(true, animated: true, completion: nil)
                duration = 0.5
            } else {
                cellHeights[indexPath.row] = C.CellHeight.close
                cell.unfold(false, animated: true, completion: nil)
                duration = 0.8
            }
    
            UIView.animateWithDuration(duration, delay: 0, options: .CurveEaseOut, animations: { _ in
                tableView.beginUpdates()
                tableView.endUpdates()
            }, completion: nil)
        }
    
        func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
            if case let cell as FoldingCell = cell {
                if cellHeights[indexPath.row] == C.CellHeight.close {
                    cell.setSelected(false, animated: false)
                } else {
                    cell.setSelected(true, animated: false)
                }
            }
        }
    }
    

    Hopefully, you will help me to use this nice lib.

    Thanks.

    opened by sho-v00 7
  • anchorPoint modifications in FoldingCell.swift causes shifts in subviews of foregroundView

    anchorPoint modifications in FoldingCell.swift causes shifts in subviews of foregroundView

    Hello!

    I recently got this library up and running in my project, and I just want to start by thanking @Ramotion for creating this library. It's amazing!

    This is a mockup I've drawn in sketch delineating what I'd like to accomplish: screen shot 2016-08-15 at 7 47 11 pm

    The issue I have at hand is that the default library appears to be defining an anchorPoint (shown below) that puts my content in the wrong position.

    foregroundView.layer.anchorPoint = CGPoint.init(x: 0.5, y: 1)

    Here's a visual showing the green UIView covered by the NavigationBar: screen shot 2016-08-15 at 7 43 58 pm

    If I remove the line of code shown above, I get it to work (partially). The other problem is that the foregroundView exceeds my defined height. screen shot 2016-08-15 at 7 45 49 pm

    To give some more context, I've set the cell heights programmatically in my primary TableViewController as 120 pixels:

    var itemHeight = [CGFloat](count: 1, repeatedValue: 120.0)

    I define the layout constraints of my foreground/container views in TestCell.swift which inherits from FoldingCell.swift, the code below is supposed to set the foregroundView height at 110 pixels. screen shot 2016-08-15 at 8 06 20 pm

    How might I be able to resolve this issue? Any help is appreciated!

    opened by ghost 7
  • How to get rotated views to fold?

    How to get rotated views to fold?

    How do I get the folding animation to happen on multiple views. Right now I have 3 views in the container, and I set the class of the last 2 to Rotated View, and added tags 1 and 2. Then I set the constraints. The animation is only folding once though when it should be folding 3 times. What am I missing?

    opened by hyunsbuns 7
  • Foreground and Container constraints

    Foreground and Container constraints

    My foreground and container constraints are nil. I follow the instructions on tutoriaI and I don't know the reason

    Check the screenshots screen shot 2016-05-12 at 12 12 59 screen shot 2016-05-12 at 12 13 37 screen shot 2016-05-12 at 12 13 46 screen shot 2016-05-12 at 12 14 06

    Thanks for helping

    opened by matheusleite 6
  • Bounce Animation

    Bounce Animation

    I loved the second animation in the GIF, but don't see any code on implementing it. Has anyone figured out how to implement it? and is there a reason you guys didn't post the code - any issues with the animation itself?

    Thanks for everything I love the work you guys are sharing with us!

    question 
    opened by nanohaddad 6
  • Folding-cell demoObjectiveC cant compile

    Folding-cell demoObjectiveC cant compile

    Awesome Demo. It has an issue in objectiveC Demo. How to fix this issues?

    /User/folding-cell/FoldingCell/FoldingCell-DemoObjc/TableViewController.m:62:27: No visible @interface for 'FoldingCell' declares the selector 'selectedAnimation:animated:completion:'

    /User/folding-cell/FoldingCell/FoldingCell-DemoObjc/TableViewController.m:64:27: No visible @interface for 'FoldingCell' declares the selector 'selectedAnimation:animated:completion:'

    /User/folding-cell/FoldingCell/FoldingCell-DemoObjc/TableViewController.m:88:9: No visible @interface for 'FoldingCell' declares the selector 'setDurationsForExpandedState:'

    /User/folding-cell/FoldingCell/FoldingCell-DemoObjc/TableViewController.m:89:9: No visible @interface for 'FoldingCell' declares the selector 'setDurationsForCollapsedState:'

    /User/folding-cell/FoldingCell/FoldingCell-DemoObjc/TableViewController.m:111:11: No visible @interface for 'FoldingCell' declares the selector 'selectedAnimation:animated:completion:'

    /User/folding-cell/FoldingCell/FoldingCell-DemoObjc/TableViewController.m:115:11: No visible @interface for 'FoldingCell' declares the selector 'selectedAnimation:animated:completion:'

    opened by skparticles 5
  • Crash regrading container height

    Crash regrading container height

    My foreground view height is 170, container count = 2, so i made my container height = 340 but it is still crashing. I tried different heights between 300 to 400. I followed as per the formula

    When itemCount equal 2 your containerView.heigh must equal 2 * foregroundView.height When itemCount greater 2 your contanerView.height must bigger when 2 * foregroundView.height Solution plz?

    opened by karnakar 5
  • Labels show wrong row while cell is opening

    Labels show wrong row while cell is opening

    I have a tableview made of folding cells. Each cell has a label which shows a row of the indexPath.row of the tableview. Clicking on the cell the cell "opens" showing the same label of the closed cell and other information related to the same indexPath.row. While I scroll the tableview everything is perfect. On the contrary while the cell is opening the labels show the wrong text (they show the text of other rows not the previous or the following, the index is related to a text that is further up or down). Of course the cell is completely open everything is fine also while I scroll the tableview.

    Any idea how to solve this? Thanks

    opened by sniis84 5
  • "contanerView.height too high"

    Hey,

    i keep getting this message when running my app. kCloseCellHeight and kOpenCellHeight are greater than the storyboard constraint. Any ideas what could be wrong?

    Thanks a lot

    opened by knappsimon 5
  • Proposed an animation fix

    Proposed an animation fix

    Summary

    1. Fixed scroll-to-bottom condition so that both sides are relative y-coordinates. cell.frame.maxY > tableView.frame.maxY should be cell.frame.maxY > tableView.frame.maxY + tableView.contentOffset.y
    2. Enabled scrolling to the top of the cell, when some of top part of this cell is across the upper edge of the table view (that is, hidden) and is tapped to unfold.
    opened by congliu0704 0
  • Documentation the

    Documentation the "5.5 Control if the cell is open or closed" doesn't exist

    I tried to upgrade an old version that I used the selectedAnimation() method but the new version has no such method while the docs still suggest using it.

    opened by zeevvax 0
  • Want to use in swift ui

    Want to use in swift ui

    I've been wanting to use this library for ages but I haven't found anything on how to integrate it into swiftui. If theres any way, help would be much appreciated

    opened by ch05enOne 0
  • Not able to set dynamic cell height

    Not able to set dynamic cell height

    @0ber @RamotionDev @Juriv @igork-ramotion #Urgent #important

    I tried many way to set dynamic height on run time but not able to set it. if I remove fix height and set UITableView.automaticDimension then open cell size also calculated.

    enhancement 
    opened by vipinsaini0 1
  • Dark mode on folding cell?

    Dark mode on folding cell?

    Hi, Thanks for the amazing library you made! I use the demo app from folding cell, but I found that if the user turns on the dark mode, the folding cell foreground and background view will not adopt the dark mode. It will still be white or the original background color. Meanwhile, the label on the folding cell is white in dark mode. Could you please take a look at this? Thanks in advance

    enhancement 
    opened by wbwxshao 0
Releases(5.0.2)
Owner
Ramotion
UI Engineering, UI/UX Design and Front-End Development Agency
Ramotion
✨ Awesome expandable, collapsible tableview cell for iOS written in Swift 5

ExpandableCell Intoduction Fully refactored YNExapnadableCell with more concise, bug free. Easiest usage of expandable & collapsible cell for iOS, wri

Kyle Yi 728 Jan 1, 2023
`SimpleExpandableView` is a SwiftUI view which can collapse and expand the content

SimpleExpandableView 中文说明 ExpandableView structure Example ExpandableView( headerSize: CGSize(width: 250.0, height: 50.0), cardSize: CGSize(wi

Tomortec 5 Oct 6, 2022
RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion

ANIMATED TAB BAR Swift UI module library for adding animation to iOS tabbar items and icons.

Ramotion 11k Jan 8, 2023
UITableView cell cache that cures scroll-lags on cell instantiating

UITableView + Cache https://github.com/Kilograpp/UITableView-Cache UITableView cell cache that cures scroll-lags on a cell instantiating. Introduction

null 73 Aug 6, 2021
:octocat:💧 A slider widget with a popup bubble displaying the precise value selected. Swift UI library made by @Ramotion

FLUID SLIDER A slider widget with a popup bubble displaying the precise value selected written on Swift. We specialize in the designing and coding of

Ramotion 1.9k Dec 23, 2022
⭕️ CircleMenu is a simple, elegant UI menu with a circular layout and material design animations. Swift UI library made by @Ramotion

CIRCLE MENU Simple, elegant UI menu with a circular layout and material design animations We specialize in the designing and coding of custom UI for M

Ramotion 3.4k Dec 29, 2022
💧 A slider widget with a popup bubble displaying the precise value selected. Swift UI library made by @Ramotion

FLUID SLIDER A slider widget with a popup bubble displaying the precise value selected written on Swift. We specialize in the designing and coding of

Ramotion 1.9k Dec 23, 2022
A custom modal transition that presents and dismiss a controller with an expanding bubble effect.

A custom modal transition that presents and dismiss a controller inside an expanding and shrinking bubble. Screenshot Usage Install through CocoaPods:

Andrea Mazzini 3.3k Dec 28, 2022
A custom modal transition that presents a controller with an expanding effect while sliding out the presenter remnants.

DAExpandAnimation A custom modal transition that presents a controller with an expanding effect while sliding out the presenter remnants. Screenshot I

Denis Avdeev 578 Nov 29, 2022
:octocat: AdaptiveController is a 'Progressive Reduction' Swift UI module for adding custom states to Native or Custom iOS UI elements. Swift UI component by @Ramotion

ADAPTIVE TAB BAR 'Progressive Reduction' module for adding custom states to Native or Custom UI elements. We specialize in the designing and coding of

Ramotion 2k Nov 9, 2022
Template auto layout cell for automatically UITableViewCell height calculating

UITableView-FDTemplateLayoutCell Overview Template auto layout cell for automatically UITableViewCell height calculating. Basic usage If you have a se

null 10k Dec 31, 2022
App uses API to display information about City and State user using expandable table cell

Expandable Table Cell iOS App App uses API to display information about City and State user using expandable table cell Implemented Using MVVM with Cl

null 2 Nov 30, 2021
a TableView have thumbnail cell only, and you can use gesture let it expands other expansionView, all diy

ZYThumbnailTableView #####可展开型预览TableView,开放接口,完全自由定制 #####An expandable preview TableView, custom-made all the modules completely with open API you c

null 950 Oct 17, 2022
Easy UITableView drag-and-drop cell reordering

SwiftReorder NOTE: Some users have encountered compatibility issues when using this library with recent versions of iOS. For apps targeting iOS 11 and

Adam Shin 378 Dec 13, 2022
A UITableView extension that enables cell insertion from the bottom of a table view.

ReverseExtension UITableView extension that enabled to insert cell from bottom of tableView. Concept It is difficult to fill a tableview content from

Taiki Suzuki 1.7k Dec 15, 2022
✨ Awesome expandable, collapsible tableview cell for iOS written in Swift 4

USE ExpandableCell. New version of this library. YNExpandableCell Updates See CHANGELOG for details Intoduction Easiest usage of expandable & collapsi

Kyle Yi 457 Dec 26, 2022
✨ Awesome expandable, collapsible tableview cell for iOS written in Swift 5

ExpandableCell Intoduction Fully refactored YNExapnadableCell with more concise, bug free. Easiest usage of expandable & collapsible cell for iOS, wri

Kyle Yi 728 Jan 1, 2023
Simple Catalyst example (Mac idiom) of a grid-based app populated with photos, with dynamic cell layout switching

Catalyst Photo Grid Simple Catalyst example (Mac idiom) of a grid-based app populated with photos that can animate its cells between two different lay

Steven Troughton-Smith 56 Nov 14, 2022
Hotels By Location - Click on the table view cell will navigate to hotel url

HotelsByLocation About This is the final project of IOS Nano Degree. Longpress or search locations. It'll drop a pin on the map. Click on the annotaio

HWYS 0 Jan 15, 2022