Giter Site home page Giter Site logo

ramotion / folding-cell Goto Github PK

View Code? Open in Web Editor NEW
10.2K 273.0 1.2K 23 MB

:octocat: ๐Ÿ“ƒ FoldingCell is an expanding content cell with animation made by @Ramotion

Home Page: https://www.ramotion.com/folding-cell/

License: MIT License

Swift 82.71% Ruby 1.27% Objective-C 16.02%
swift ui animation library ios material-design

folding-cell's Introduction

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.

folding-cell's People

Contributors

0ber avatar aleksei1000000 avatar alexmik89 avatar artemkyslicyn avatar dershowitz011 avatar grodowski avatar hu55a1n1 avatar igork-ramotion avatar ikolpachkov avatar juriv avatar lambdadigamma avatar markj avatar mohpor avatar ohyes1h avatar peterstaev avatar qasimsina avatar radarhere avatar ramotiondev avatar ramotionrussell avatar ronnielsen avatar tangchunhin1628 avatar zhongwuzw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

folding-cell's Issues

Animation Crash

Hi,

Thanks for providing the animated cell, i changed some pf the properties in storyboard it lead me to [UIView transform3d]: unrecognized selector sent to instance crash.

How can i do stepwise in unfolding stage similar to folding process

Unfolding Animation Slightly Off

When I open or close the cell, I noticed that the unfolding animation is slightly to the left of where it should be. Is there a way to fix this?

Rounded Edges

So, I was able to get the top corners rounded (following the project you uploaded). Any reason why it is cutting off the bottom rounded corners?
messages image 2857556704

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

How do you control UI from DemoCell Class?

Dear Ramotion

I was just wondering how to control UI (for example a textfield that is in the cell) from the DemoCell class. It appears that the FoldingCell (what DemoCell inherits from) does not allow this. Please help. Thanks.

"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

Possible No Storyboard?

Hi, this looks really cool!

But I am having trouble to implement this to my app with no storyboard?

Could you please provide me with sample project where is no storyboard?

Huge thanks!

Where to add "animationDuration" method?

I created everything with the storyboard, justing setting the cell to FoldingCell, where do I add this method?

`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]
}`

Memory spike in pb_takeSnapshot function

Hey there! Love the work! Noticed some unusual memory behavior.
screen shot 2016-06-22 at 10 19 52 am

The memory usage increases by a lot every time I tap to open a cell (which will then load images with SDWebImage, as well as other data from the server), but it never comes down. Now, I understand dealing with images is expensive, but is there a way to work around this issue? Please let me know what you think.

Make IBOutlets public

Make containerView and foregroundView public because now they are internal so we can't use them in subclass as you used them in demo project to change maskToBounds and cornerRadius (you could because you have everything in the same module in demo project)

Slow

Hey,

is it normal that when i launch my tableview with folding-cell it's takin' 3 seconds maybe 4 for launch? :/

Sad :(
Thanks

Swift 3 and Xcode 8

When I updated to Swift 3 and Xcode 8, it seemed to break the small views. When the cell is opened, everything looks fine, but when closed the cells are only showing the bottom halves.
img_2466
img_2467

Height of Container View is shorten

Awesome work, I am using your code and it helpful for my requirement, but I have two issue like

  • I have description label in containerView in which I have to show the only 3 line with more button, when I click on that more button and increase the height or I set UITableViewAutomaticDimension then it shrink height.
  • In containerView, I have Like button as I hit the like button, I am scrolling the tableview then click on fold button then that cell is freeze not click or user interaction working on that cell

Please guid me where is my mistake

Thanks :)

fatal error: Index out of range

Hello First of all i want to thank you on this amazing project.
and second of all i want to ask about an issue that i encounter which is I keep having an error about the range on this code:

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

I want to know exactly where is the problem and i have another questions if it possible when i downloaded the project to my desktop and examine the design i notice that showing the design as in the image which showing the map is not really in the demo so if how i can apply it on the demo, that is it and thank you again

Description

Project should have a description, such as
TableViewCell replacement with parallax detail view for Swift

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!

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?

What line or function creates the cell?

Dear Ramotion and folding-cell lovers

I am trying to create a basic table in my app that uses folding cell. In order to do this I have one question: What line or function actually creates the cell? For example, in the default Master-Detail application, it is the insertNewObject function. The reason I would like to know this is because I want to make it so when the user hits a button, a new cell is created. Thanks.

unable to simultaneously satisfy constraints

I have a foreground view with height of 100 and container view with height 200 ,I have all the needed constrains but i have this strange error.
everything is working fine but this warning is not ok

2016-09-04 20:43:03.447 TMDB[28304:3323822] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x7fca0bd54cc0 V:[UIView:0x7fca0bd50f70(200)]>",
    "<NSLayoutConstraint:0x7fca0bd564a0 V:[UIView:0x7fca0bd50f70(84)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fca0bd54cc0 V:[UIView:0x7fca0bd50f70(200)]>

this is my layout:
screen shot 2016-09-04 at 8 46 15 pm

Warning report creating from scratch

I followed the instructions and I achieved the effect I wanted, but I still get this warning that I don't understand how to remove.

<Error>: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Could you please help?

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!

Docs !!

This seems really nice but for someone new to swift the documents are really hard to follow.

How to refresh animation views

My app has content that changes within the cells quite frequently. If a change happens while the cell is expanded, then the cell is closed, during the animations the content changes back to the old values. Is there a way to refresh what is shown during the animations?

Thanks for the great work BTW!

Dramatically slow

Hello! Any ideas to use multi-threading or etc to faster the set-up/init time? The set-up time grows from 6s(iphone 6s) to 30/40s (iphone 5c/4s)!
What can be a problem? How to solve the time spreading?
Anyway tnx for response!

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

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?

Customise Height of Different 'Folds'

How would we go about customising the height of each of the folds of the cell animation @Pakhaliuk ? I know I can change the height of each of the views within the 'open' cell but then the animation still loads them at the pre-defined (and seemingly same height for every subview).

Can we edit the animation and if so, how?
Thanks very much for being awesome and sharing this!

Crashing on animations

I'm a novice programmer, but I'm pretty sure I'm doing all the steps right... keeps crashing when selecting the rotated view: "fatal error: Array index out of range"

All the breakpoints seem to be happening on animation lines:

2 0x00000001002eb878 in FoldingCell.openAnimation(completion : () -> ()?) -> () at /Users/Brabble/Documents/Squad/Pods/FoldingCell/FoldingCell/FoldingCell/FoldingCell/FoldingCell.swift:318

3 0x00000001002ea948 in FoldingCell.selectedAnimation(Bool, animated : Bool, completion : () -> ()?) -> () at /Users/Brabble/Documents/Squad/Pods/FoldingCell/FoldingCell/FoldingCell/FoldingCell/FoldingCell.swift:237

4 0x00000001000d2930 in DemoTableViewController.tableView(UITableView, didSelectRowAtIndexPath : NSIndexPath) -> () at /Users/Brabble/Documents/Squad/Squad/DemoTableViewController.swift:67

Am I missing something?

Getting run time error

Hi,

I am getting the following run time error while trying to run the app.

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Must translate autoresizing mask into constraints to have _setHostsLayoutEngine:YES.'

Please help me

Figured it somehow. I am getting this error now

screen shot 2016-08-23 at 8 07 48 pm
screen shot 2016-08-23 at 8 08 01 pm

What line or function creates the cell?

Dear Ramotion and folding-cell lovers

I am trying to create a basic table in my app that uses folding cell. In order to do this I have one question: What line or function actually creates the cell? For example, in the default Master-Detail application, it is the insertNewObject function. The reason I would like to know this is because I want to make it so when the user hits a button, a new cell is created. Thanks.

Specify background cover of fold

I have a slight issue with this framework, my "cards" are all with white background but when folding or unfolding the background of the other face of the card is a wired brown! How did this happen? I mean I didn't even specific any colour! Here are some screenshots to help clarify.

I also have a bit of a problem with some constrains, it gives me the "Unable to simultaneously satisfy constraints" look, it also seems to happen in each "card":

2016-06-06 23:05:45.912 GL Dash[542:87484] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x127678ec0 V:[UIView:0x1276654c0(350)]>",
    "<NSLayoutConstraint:0x1276beef0 V:[UIView:0x1276654c0(132)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x127678ec0 V:[UIView:0x1276654c0(350)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-06-06 23:05:45.914 GL Dash[542:87484] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 

        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x1276beef0 V:[UIView:0x1276654c0(132)]>",
    "<NSLayoutConstraint:0x1276c2010 V:[UIView:0x1276654c0(75)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1276beef0 V:[UIView:0x1276654c0(132)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

Tiago

img_3299
img_3300
img_3301
img_3302

fatal error: set identifier: file FoldingCell.swift

I am getting the above mentioned error, seems like a method, configureDefaultState(), within FoldingCell.swift, is checking for "ForegroundViewTop" and "ContainerViewTop".

Maybe clearer documentation on how to add those 2 in the storyboard.

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.