Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd71f7ba65 | ||
|
|
fecd05d93f |
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'FoldingCell'
|
||||
s.version = '2.1.2'
|
||||
s.version = '2.1.3'
|
||||
s.summary = 'UITableViewCell with folding animation.'
|
||||
s.homepage = 'https://github.com/Ramotion/folding-cell'
|
||||
s.license = 'MIT'
|
||||
|
||||
@@ -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,9 +501,11 @@ 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)
|
||||
|
||||
@@ -517,4 +518,5 @@ extension UIView {
|
||||
|
||||
return image
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user