Compare commits

..
4 Commits
Author SHA1 Message Date
Abdurahim Jauzee dd71f7ba65 update podspec 2017-05-31 18:38:52 +03:00
Abdurahim Jauzee fecd05d93f - add unfold(_:animated:completion) method
- deprecate `selectedAnimation` because it’s name is not clear
- minor improvements
2017-05-31 18:38:06 +03:00
Abdurahim Jauzee 77e99b8708 update podspec 2017-05-31 12:41:22 +03:00
Abdurahim Jauzee 5254378736 remove unnecessary guard statement 2017-05-31 12:39:34 +03:00
2 changed files with 46 additions and 48 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FoldingCell'
s.version = '2.1.1'
s.version = '2.1.3'
s.summary = 'UITableViewCell with folding animation.'
s.homepage = 'https://github.com/Ramotion/folding-cell'
s.license = 'MIT'
+45 -47
View File
@@ -93,7 +93,7 @@ open class FoldingCell: UITableViewCell {
}
containerViewTop.constant = foregroundViewTop.constant
containerView.alpha = 0;
containerView.alpha = 0
if let height = (foregroundView.constraints.filter { $0.firstAttribute == .height && $0.secondItem == nil}).first?.constant {
foregroundView.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
@@ -101,7 +101,7 @@ open class FoldingCell: UITableViewCell {
}
foregroundView.layer.transform = foregroundView.transform3d()
createAnimationView();
createAnimationView()
self.contentView.bringSubview(toFront: foregroundView)
}
@@ -133,7 +133,7 @@ open class FoldingCell: UITableViewCell {
for view in animationViewSuperView.filter({$0 is RotatedView}) {
view.alpha = 0;
}
} else { // close
} else {
for case let view as RotatedView in animationViewSuperView.filter({$0 is RotatedView}) {
if animationType == .open {
view.alpha = 0
@@ -146,7 +146,6 @@ open class FoldingCell: UITableViewCell {
}
func createAnimationView() {
animationView = UIView(frame: containerView.frame)
animationView?.layer.cornerRadius = foregroundView.layer.cornerRadius
animationView?.backgroundColor = .clear
@@ -241,7 +240,7 @@ open class FoldingCell: UITableViewCell {
rotatedView.tag = tag
yPosition += itemHeight
tag += 1;
tag += 1
}
containerView.alpha = 0;
@@ -270,6 +269,21 @@ open class FoldingCell: UITableViewCell {
// MARK: public
/// Unfold cell.
///
/// - Parameters:
/// - value: unfold = true; collapse = false.
/// - animated: animate changes.
/// - completion: A block object to be executed when the animation sequence ends.
open func unfold(_ value: Bool, animated: Bool = true, completion: ((Void) -> Void)? = nil) {
if animated {
value ? openAnimation(completion) : closeAnimation(completion)
} else {
foregroundView.alpha = value ? 0 : 1
containerView.alpha = value ? 1 : 0
}
}
/**
Open or close cell
@@ -277,34 +291,19 @@ open class FoldingCell: UITableViewCell {
- parameter animated: Specify true if you want to animate the change in visibility or false if you want immediately.
- parameter completion: A block object to be executed when the animation sequence ends.
*/
@available(iOS, deprecated, message: "Use unfold(_:animated:completion) method instead.")
open func selectedAnimation(_ isSelected: Bool, animated: Bool, completion: ((Void) -> Void)?) {
if isSelected {
if animated {
containerView.alpha = 0;
openAnimation(completion)
} else {
foregroundView.alpha = 0
containerView.alpha = 1;
}
} else {
if animated {
closeAnimation(completion)
} else {
foregroundView.alpha = 1;
containerView.alpha = 0;
}
}
unfold(isSelected, animated: animated, completion: completion)
}
open func isAnimating()->Bool {
open func isAnimating() -> Bool {
return animationView?.alpha == 1 ? true : false
}
open var isUnfolded = false
// MARK: Animations
open func animationDuration(_ itemIndex: NSInteger, type: AnimationType)-> TimeInterval {
open func animationDuration(_ itemIndex: NSInteger, type: AnimationType) -> TimeInterval {
return type == .close ? durationsForCollapsedState[itemIndex] : durationsForExpandedState[itemIndex]
}
@@ -322,7 +321,7 @@ open class FoldingCell: UITableViewCell {
}
func openAnimation(_ completion: ((Void) -> Void)?) {
isUnfolded = true
removeImageItemsFromAnimationView()
addImageItemsToAnimationView()
@@ -330,12 +329,12 @@ open class FoldingCell: UITableViewCell {
return
}
animationView.alpha = 1;
containerView.alpha = 0;
animationView.alpha = 1
containerView.alpha = 0
let durations = durationSequence(.open)
var delay: TimeInterval = 0
var delay: TimeInterval = 0
var timing = kCAMediaTimingFunctionEaseIn
var from: CGFloat = 0.0;
var to: CGFloat = -CGFloat.pi / 2
@@ -358,22 +357,22 @@ open class FoldingCell: UITableViewCell {
delay += durations[index]
}
let firstItemView = animationView.subviews.filter{$0.tag == 0}.first
let firstItemView = animationView.subviews.filter { $0.tag == 0 }.first
firstItemView?.layer.masksToBounds = true
DispatchQueue.main.asyncAfter(deadline: .now() + durations[0], execute: {
firstItemView?.layer.cornerRadius = 0
})
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
self.animationView?.alpha = 0
self.containerView.alpha = 1
completion?()
})
}
}
func closeAnimation(_ completion: ((Void) -> Void)?) {
isUnfolded = false
removeImageItemsFromAnimationView()
addImageItemsToAnimationView()
@@ -381,14 +380,14 @@ open class FoldingCell: UITableViewCell {
fatalError()
}
animationView?.alpha = 1;
containerView.alpha = 0;
animationView?.alpha = 1
containerView.alpha = 0
var durations: [TimeInterval] = durationSequence(.close).reversed()
var delay: TimeInterval = 0
var delay: TimeInterval = 0
var timing = kCAMediaTimingFunctionEaseIn
var from: CGFloat = 0.0;
var from: CGFloat = 0.0
var to: CGFloat = CGFloat.pi / 2
var hidden = true
configureAnimationItems(.close)
@@ -412,7 +411,7 @@ open class FoldingCell: UITableViewCell {
completion?()
})
let firstItemView = animationView?.subviews.filter{$0.tag == 0}.first
let firstItemView = animationView?.subviews.filter { $0.tag == 0 }.first
firstItemView?.layer.cornerRadius = 0
firstItemView?.layer.masksToBounds = true
if let durationFirst = durations.first {
@@ -436,7 +435,7 @@ open class RotatedView: UIView {
view.backgroundColor = color
view.layer.anchorPoint = CGPoint.init(x: 0.5, y: 1)
view.layer.transform = view.transform3d()
view.translatesAutoresizingMaskIntoConstraints = false;
view.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(view)
backView = view
@@ -502,23 +501,22 @@ extension RotatedView: CAAnimationDelegate {
self.layer.shouldRasterize = false
self.rotatedX(CGFloat(0))
}
}
extension UIView {
private extension UIView {
func pb_takeSnapshot(_ frame: CGRect) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0.0)
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0)
guard let context = UIGraphicsGetCurrentContext() else { return nil }
context.translateBy(x: frame.origin.x * -1, y: frame.origin.y * -1)
guard let currentContext = UIGraphicsGetCurrentContext() else {
return nil
}
self.layer.render(in: currentContext)
layer.render(in: context)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}