Compare commits

...
9 Commits
Author SHA1 Message Date
Alex ab56f9ad83 Merge pull request #83 from markj/master
Support different animationDurations for opening / closing cells
2016-11-30 15:57:33 +02:00
Mark Johnson 47397e60c6 Make durationSequence respect different animation times for opening or closing a cell 2016-11-30 13:38:45 +00:00
aleksei1000000 63e9ff9410 Update README.md 2016-10-17 10:01:43 +03:00
aleksei1000000 6b95f91f86 Update README.md 2016-10-14 14:42:24 +03:00
aleksei1000000 c439f9af9b Update README.md 2016-10-14 14:08:24 +03:00
Alex.k 5bd466425f updated readme 2016-10-13 14:16:56 +03:00
Alex 4b152e7901 Update README.md 2016-10-13 10:45:59 +03:00
Alex.k 756c665759 Fixes #48 2016-10-11 16:12:54 +03:00
Alex.k 29f151dcef update readme and podspec 2016-10-11 15:50:15 +03:00
4 changed files with 23 additions and 29 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FoldingCell'
s.version = '2.0.0'
s.version = '2.0.1'
s.summary = 'UITableViewCell with folding animation.'
s.homepage = 'https://github.com/Ramotion/folding-cell'
s.license = 'MIT'
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="0cn-rv-Emg">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@@ -310,7 +310,7 @@ open class FoldingCell: UITableViewCell {
func durationSequence(_ type: AnimationType)-> [TimeInterval] {
var durations = [TimeInterval]()
for index in 0..<itemCount-1 {
let duration = animationDuration(index, type: .open)
let duration = animationDuration(index, type: type)
durations.append(TimeInterval(duration / 2.0))
durations.append(TimeInterval(duration / 2.0))
}
+21 -26
View File
@@ -10,9 +10,9 @@
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Analytics](https://ga-beacon.appspot.com/UA-84973210-1/ramotion/folding-cell)](https://github.com/igrigorik/ga-beacon)
## About
This project is maintained by Ramotion, an agency specialized in building dedicated engineering teams and developing custom software.<br><br> [Contact our team](https://business.ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell-contact-us) and we’ll help you work with the best engineers from Eastern Europe.
This project is maintained by Ramotion, Inc.<br>
We specialize in the designing and coding of custom UI for Mobile Apps and Websites.<br><br>**Looking for developers for your project?** [[▶︎CONTACT OUR TEAM◀︎](http://business.ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell-contact-us/#Get_in_Touch)]
[![Animation](https://raw.githubusercontent.com/Ramotion/folding-cell/master/Screenshots/folding-cell.gif)](https://dribbble.com/shots/2121350-Delivery-Card)
@@ -29,16 +29,18 @@ Just add the FoldingCell.swift file to your project.
or use [CocoaPods](https://cocoapods.org) with Podfile:
``` ruby
pod 'FoldingCell'
pod 'FoldingCell' '~> 1.0.0' swift 2.2
pod 'FoldingCell' '~> 2.0.1' swift 3
```
or [Carthage](https://github.com/Carthage/Carthage) users can simply add Mantle to their `Cartfile`:
```
github "Ramotion/folding-cell" "~> 1.0.0" swift 2.2
github "Ramotion/folding-cell"
github "Ramotion/folding-cell" "~> 2.0.0" swift 3
```
or just drag and drop FoldingCell.swift file to your project
## Solution
![Solution](https://raw.githubusercontent.com/Ramotion/folding-cell/master/Tutorial-resources/Solution.png)
## Usage
@@ -76,24 +78,17 @@ Ok, we've finished configuring the cell.
5.1) Add constants:
``` swift
let kCloseCellHeight: CGFloat = *** // equal or greater foregroundView height
let kOpenCellHeight: CGFloat = *** // equal or greater containerView height
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
5.2) Add property for calculate cells height
``` swift
var cellHeights = [CGFloat]()
```
create in viewDidLoad:
``` swift
override func viewDidLoad() {
super.viewDidLoad()
for _ in 0...kRowsCount {
cellHeights.append(kCloseCellHeight)
}
}
var cellHeights = (0..<CELLCOUNT).map { _ in C.CellHeight.close }
```
5.3) Override method:
@@ -106,7 +101,9 @@ Ok, we've finished configuring the cell.
5.4) Added code to method:
``` swift
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath) as! FoldingCell
guard case let cell as FoldingCell = tableView.cellForRowAtIndexPath(indexPath) else {
return
}
var duration = 0.0
if cellHeights[indexPath.row] == kCloseCellHeight { // open cell
@@ -119,7 +116,7 @@ Ok, we've finished configuring the cell.
duration = 1.1
}
UIView.animateWithDuration(duration, delay: 0, options: .CurveEaseOut, animations: { () -> Void in
UIView.animateWithDuration(duration, delay: 0, options: .CurveEaseOut, animations: { _ in
tableView.beginUpdates()
tableView.endUpdates()
}, completion: nil)
@@ -129,10 +126,8 @@ Ok, we've finished configuring the cell.
``` swift
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if cell is FoldingCell {
let foldingCell = cell as! FoldingCell
if cellHeights![indexPath.row] == kCloseCellHeight {
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)