Compare commits

..
11 Commits
Author SHA1 Message Date
Alex.k e5c63c9812 Fixes #5 2016-02-05 11:04:55 +03:00
Alex.k 4ec5646fa1 Revert "Fixes #45"
This reverts commit 20d7be5ca0.
2016-02-05 11:03:06 +03:00
Alex.k 20d7be5ca0 Fixes #45 2016-02-05 11:02:30 +03:00
Alex 0871b243b3 Update README.md 2016-02-04 17:11:35 +03:00
Alex.k d41c599568 update podspect 2016-02-04 17:08:45 +03:00
Alex.k e720eaf3f3 common improves 2016-02-04 17:07:20 +03:00
Alex 4c3d646349 Update .travis.yml 2016-02-03 15:41:06 +03:00
Alex.k 4d41164378 changed version 2016-02-03 14:14:27 +03:00
Alex.k aa490544c2 improve isAnimating method 2016-02-03 10:24:43 +03:00
Juri Vasylenko 835ff54cbb Update README.md 2016-02-01 12:12:31 +03:00
Alex f65b92ffdf Merge pull request #1 from Ramotion/docs_update
Docs update
2016-02-01 11:22:42 +03:00
4 changed files with 86 additions and 43 deletions
+1 -1
View File
@@ -3,4 +3,4 @@ language: objective-c
xcode_project: FoldingCell/FoldingCell.xcodeproj
xcode_scheme: FoldingCell
xcode_sdk: iphonesimulator9.1
xcode_sdk: iphonesimulator
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FoldingCell'
s.version = '0.3'
s.version = '0.5'
s.summary = 'UITableViewCell with folding animation.'
s.homepage = 'https://github.com/Ramotion/folding-cell'
s.license = 'MIT'
@@ -27,8 +27,8 @@ public class FoldingCell: UITableViewCell {
public typealias CompletionHandler = () -> Void
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var foregroundView: RotatedView!
@IBOutlet weak public var containerView: UIView!
@IBOutlet weak public var foregroundView: RotatedView!
var animationView: UIView?
@IBInspectable var itemCount: NSInteger = 2 //count of folding
@@ -61,14 +61,18 @@ public class FoldingCell: UITableViewCell {
let foregroundTopConstraint = self.contentView.constraints.filter{ $0.identifier == "ForegroundViewTop"}.first
let containerViewTopConstraint = self.contentView.constraints.filter{ $0.identifier == "ContainerViewTop"}.first
assert(foregroundTopConstraint != nil, "set identifier")
assert(containerViewTopConstraint != nil, "set identifier")
guard let foregroundConstraint = foregroundTopConstraint else {
fatalError("set identifier")
}
guard let containerConstraint = containerViewTopConstraint else {
fatalError("set identifier")
}
containerViewTopConstraint!.constant = foregroundTopConstraint!.constant
containerConstraint.constant = foregroundConstraint.constant
containerView.alpha = 0;
foregroundView.layer.anchorPoint = CGPoint.init(x: 0.5, y: 1)
foregroundTopConstraint!.constant += foregroundView.bounds.height / 2
foregroundConstraint.constant += foregroundView.bounds.height / 2
foregroundView.layer.transform = foregroundView.transform3d()
createAnimationView();
@@ -76,13 +80,17 @@ public class FoldingCell: UITableViewCell {
}
func createAnimationItemView()->[RotatedView] {
guard let animationView = self.animationView else {
fatalError()
}
var items = [RotatedView]()
items.append(foregroundView)
var rotatedViews = [RotatedView]()
for itemView in animationView!.subviews.filter({$0 is RotatedView}).sort({ $0.tag < $1.tag }) as! [RotatedView] {
for case let itemView as RotatedView in animationView.subviews.filter({$0 is RotatedView}).sort({ $0.tag < $1.tag }){
rotatedViews.append(itemView)
if itemView.backView != nil {
rotatedViews.append(itemView.backView!)
if let backView = itemView.backView {
rotatedViews.append(backView)
}
}
items.appendContentsOf(rotatedViews)
@@ -90,12 +98,17 @@ public class FoldingCell: UITableViewCell {
}
func configureAnimationItems(animationType: AnimationType) {
guard let animationViewSuperView = animationView?.subviews else {
fatalError()
}
if animationType == .Open {
for view in animationView!.subviews.filter({$0 is RotatedView}) {
for view in animationViewSuperView.filter({$0 is RotatedView}) {
view.alpha = 0;
}
} else { // close
for view: RotatedView in animationView!.subviews.filter({$0 is RotatedView}) as! [RotatedView] {
for case let view as RotatedView in animationViewSuperView.filter({$0 is RotatedView}) {
if animationType == .Open {
view.alpha = 0
} else {
@@ -227,14 +240,15 @@ public class FoldingCell: UITableViewCell {
}
containerView.alpha = 0;
// added back view
var previusView: RotatedView?
for contener in animationView!.subviews.sort({ $0.tag < $1.tag }) {
if contener is RotatedView && contener.tag > 0 && contener.tag < animationView!.subviews.count {
let rotatedView = contener as! RotatedView
previusView?.addBackView(rotatedView.bounds.size.height, color: backViewColor)
previusView = rotatedView
if let animationView = self.animationView {
// added back view
var previusView: RotatedView?
for case let contener as RotatedView in animationView.subviews.sort({ $0.tag < $1.tag }) {
if contener.tag > 0 && contener.tag < animationView.subviews.count {
previusView?.addBackView(contener.bounds.size.height, color: backViewColor)
previusView = contener
}
}
}
@@ -266,16 +280,20 @@ public class FoldingCell: UITableViewCell {
}
public func isAnimating()->Bool {
guard animationItemViews != nil
else {
guard let animationItemViews = self.animationItemViews else {
return false
}
for item in animationItemViews! {
for item in animationItemViews {
if item.layer.animationKeys()?.count > 0 {
return true
}
}
if animationView?.alpha == 1 {
return true
}
return false
}
@@ -303,7 +321,11 @@ public class FoldingCell: UITableViewCell {
addImageItemsToAnimationView()
}
animationView?.alpha = 1;
guard let animationView = self.animationView else {
return
}
animationView.alpha = 1;
containerView.alpha = 0;
let durations = durationSequence(.Open)
@@ -314,8 +336,13 @@ public class FoldingCell: UITableViewCell {
var to: CGFloat = CGFloat(-M_PI / 2)
var hidden = true
configureAnimationItems(.Open)
for var index = 0; index < animationItemViews?.count; index++ {
let animatedView = animationItemViews![index]
guard let animationItemViews = self.animationItemViews else {
return
}
for var index = 0; index < animationItemViews.count; index++ {
let animatedView = animationItemViews[index]
animatedView.foldingAnimation(timing, from: from, to: to, duration: durations[index], delay: delay, hidden: hidden)
@@ -326,10 +353,13 @@ public class FoldingCell: UITableViewCell {
delay += durations[index]
}
let firstItemView = animationView!.subviews.filter{$0.tag == 0}.first
firstItemView!.layer.masksToBounds = true
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(durations[0] * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
firstItemView!.layer.cornerRadius = 0
let firstItemView = animationView.subviews.filter{$0.tag == 0}.first
if let first = firstItemView {
first.layer.masksToBounds = true
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(durations[0] * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
first.layer.cornerRadius = 0
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
self.animationView?.alpha = 0
@@ -357,9 +387,12 @@ public class FoldingCell: UITableViewCell {
var hidden = true
configureAnimationItems(.Close)
for var index = 0; index < animationItemViews?.count; index++ {
let animatedView = animationItemViews?.reverse()[index]
guard let animatedView = animationItemViews?.reverse()[index] else {
continue
}
animatedView!.foldingAnimation(timing, from: from, to: to, duration: durations[index], delay: delay, hidden: hidden)
animatedView.foldingAnimation(timing, from: from, to: to, duration: durations[index], delay: delay, hidden: hidden)
to = to == 0.0 ? CGFloat(M_PI / 2) : 0.0;
from = from == 0.0 ? CGFloat(-M_PI / 2) : 0.0;
@@ -369,14 +402,20 @@ public class FoldingCell: UITableViewCell {
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
self.animationView!.alpha = 0
if let animationView = self.animationView {
animationView.alpha = 0
}
completion?()
}
let firstItemView = animationView!.subviews.filter{$0.tag == 0}.first
firstItemView!.layer.masksToBounds = false
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64((delay - durations.last! * 1.5) * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
firstItemView!.layer.cornerRadius = self.foregroundView.layer.cornerRadius
if let animationView = self.animationView {
let firstItemView = animationView.subviews.filter{$0.tag == 0}.first
firstItemView?.layer.masksToBounds = false
if let durationLast = durations.last {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64((delay - durationLast * 1.5) * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
firstItemView?.layer.cornerRadius = self.foregroundView.layer.cornerRadius
}
}
}
}
}
@@ -465,13 +504,17 @@ extension RotatedView {
}
extension UIView {
func pb_takeSnapshot(frame: CGRect) -> UIImage {
func pb_takeSnapshot(frame: CGRect) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0.0);
let context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, frame.origin.x * -1, frame.origin.y * -1);
self.layer.renderInContext(UIGraphicsGetCurrentContext()!);
guard let currentContext = UIGraphicsGetCurrentContext() else {
return nil
}
self.layer.renderInContext(currentContext);
let image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
+3 -3
View File
@@ -18,7 +18,7 @@ Just add the FoldingCell.swift file to your project.
or use [CocoaPods](https://cocoapods.org) with Podfile:
``` ruby
pod 'FoldingCell', '~> 0.3'
pod 'FoldingCell', '~> 0.5'
```
@@ -137,8 +137,8 @@ See [LICENSE](./LICENSE) for details.
## About
The project maintained by [app development agency](http://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell) [Ramotion Inc.](http://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell)
See our other [open-source projects](https://github.com/ramotion) or [hire](http://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell) us to design, develop, and grow your product.
The project maintained by [app development agency](https://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell) [Ramotion Inc.](https://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell)
See our other [open-source projects](https://github.com/ramotion) or [hire](https://ramotion.com?utm_source=gthb&utm_medium=special&utm_campaign=foolding-cell) us to design, develop, and grow your product.
[![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=https://github.com/ramotion/foolding-cell)
[![Twitter Follow](https://img.shields.io/twitter/follow/ramotion.svg?style=social)](https://twitter.com/ramotion)