Compare commits

..
4 Commits
Author SHA1 Message Date
Abdurahim Jauzee 74e0ca7f7b update podspec 2017-05-31 12:17:09 +03:00
Abdurahim Jauzee ef3307924a use animationDuration method 2017-05-31 12:14:37 +03:00
Abdurahim Jauzee 39377ad181 revert animationDuration method for backward compatibility 2017-05-31 12:09:19 +03:00
Abdurahim Jauzee 1cf7a8124f fix typos 2017-05-31 12:08:50 +03:00
3 changed files with 27 additions and 18 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FoldingCell'
s.version = '2.1.0'
s.version = '2.1.1'
s.summary = 'UITableViewCell with folding animation.'
s.homepage = 'https://github.com/Ramotion/folding-cell'
s.license = 'MIT'
@@ -27,6 +27,11 @@ class DemoCell: FoldingCell {
super.awakeFromNib()
}
override func animationDuration(_ itemIndex: NSInteger, type: FoldingCell.AnimationType) -> TimeInterval {
let durations = [0.26, 0.2, 0.2]
return durations[itemIndex]
}
}
// MARK: - Actions ⚡️
+21 -17
View File
@@ -190,18 +190,18 @@ open class FoldingCell: UITableViewCell {
func addImageItemsToAnimationView() {
containerView.alpha = 1;
let contSize = containerView.bounds.size
let forgSize = foregroundView.bounds.size
let containerViewSize = containerView.bounds.size
let foregroundViewSize = foregroundView.bounds.size
// added first item
var image = containerView.pb_takeSnapshot(CGRect(x: 0, y: 0, width: contSize.width, height: forgSize.height))
var image = containerView.pb_takeSnapshot(CGRect(x: 0, y: 0, width: containerViewSize.width, height: foregroundViewSize.height))
var imageView = UIImageView(image: image)
imageView.tag = 0
imageView.layer.cornerRadius = foregroundView.layer.cornerRadius
animationView?.addSubview(imageView)
// added secod item
image = containerView.pb_takeSnapshot(CGRect(x: 0, y: forgSize.height, width: contSize.width, height: forgSize.height))
image = containerView.pb_takeSnapshot(CGRect(x: 0, y: foregroundViewSize.height, width: containerViewSize.width, height: foregroundViewSize.height))
imageView = UIImageView(image: image)
let rotatedView = RotatedView(frame: imageView.frame)
@@ -211,24 +211,24 @@ open class FoldingCell: UITableViewCell {
rotatedView.addSubview(imageView)
animationView?.addSubview(rotatedView)
rotatedView.frame = CGRect(x: imageView.frame.origin.x, y: forgSize.height, width: contSize.width, height: forgSize.height)
rotatedView.frame = CGRect(x: imageView.frame.origin.x, y: foregroundViewSize.height, width: containerViewSize.width, height: foregroundViewSize.height)
// added other views
let itemHeight = (contSize.height - 2 * forgSize.height) / CGFloat(itemCount - 2)
let itemHeight = (containerViewSize.height - 2 * foregroundViewSize.height) / CGFloat(itemCount - 2)
if itemCount == 2 {
// decrease containerView height or increase itemCount
assert(contSize.height - 2 * forgSize.height == 0, "contanerView.height too high")
assert(containerViewSize.height - 2 * foregroundViewSize.height == 0, "contanerView.height too high")
}
else{
// decrease containerView height or increase itemCount
assert(contSize.height - 2 * forgSize.height >= itemHeight, "contanerView.height too high")
assert(containerViewSize.height - 2 * foregroundViewSize.height >= itemHeight, "contanerView.height too high")
}
var yPosition = 2 * forgSize.height
var yPosition = 2 * foregroundViewSize.height
var tag = 2
for _ in 2..<itemCount {
image = containerView.pb_takeSnapshot(CGRect(x: 0, y: yPosition, width: contSize.width, height: itemHeight))
image = containerView.pb_takeSnapshot(CGRect(x: 0, y: yPosition, width: containerViewSize.width, height: itemHeight))
imageView = UIImageView(image: image)
let rotatedView = RotatedView(frame: imageView.frame)
@@ -248,11 +248,11 @@ open class FoldingCell: UITableViewCell {
if let animationView = self.animationView {
// added back view
var previusView: RotatedView?
for case let contener as RotatedView in animationView.subviews.sorted(by: { $0.tag < $1.tag })
where contener.tag > 0 && contener.tag < animationView.subviews.count {
previusView?.addBackView(contener.bounds.size.height, color: backViewColor)
previusView = contener
var previuosView: RotatedView?
for case let container as RotatedView in animationView.subviews.sorted(by: { $0.tag < $1.tag })
where container.tag > 0 && container.tag < animationView.subviews.count {
previuosView?.addBackView(container.bounds.size.height, color: backViewColor)
previuosView = container
}
}
animationItemViews = createAnimationItemView()
@@ -303,14 +303,18 @@ open class FoldingCell: UITableViewCell {
return animationView?.alpha == 1 ? true : false
}
// MARK: animations
// MARK: Animations
open func animationDuration(_ itemIndex: NSInteger, type: AnimationType)-> TimeInterval {
return type == .close ? durationsForCollapsedState[itemIndex] : durationsForExpandedState[itemIndex]
}
open var durationsForExpandedState: [TimeInterval] = []
open var durationsForCollapsedState: [TimeInterval] = []
func durationSequence(_ type: AnimationType)-> [TimeInterval] {
var durations = [TimeInterval]()
for i in 0..<itemCount-1 {
let duration = type == .close ? durationsForCollapsedState[i] : durationsForExpandedState[i]
let duration = animationDuration(i, type: type)
durations.append(TimeInterval(duration / 2.0))
durations.append(TimeInterval(duration / 2.0))
}