From fca83dc01de2dd76dffbe67ee7a4f56780556684 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 24 Nov 2016 15:35:20 +0800 Subject: [PATCH 1/5] bugFix: cover show style layout attribute miscalculation bugFix: cover show style layout attribute miscalculation --- MMCardView/Classes/CustomCardLayout.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMCardView/Classes/CustomCardLayout.swift b/MMCardView/Classes/CustomCardLayout.swift index 0a8f447..3a41648 100644 --- a/MMCardView/Classes/CustomCardLayout.swift +++ b/MMCardView/Classes/CustomCardLayout.swift @@ -139,7 +139,7 @@ class CustomCardLayout: UICollectionViewLayout { switch showStyle { case .cover: - if index <= shitIdx && (index >= shitIdx-2) || index == 0{ + if index <= shitIdx || index == 0{ attribute.frame = CGRect(x: currentFrame.origin.x, y: self.collectionView!.contentOffset.y, width: cellSize.width, height: cellSize.height) } else { attribute.frame = currentFrame From 4bc7eb36ea2ae210228bcb4dbd50919dbb7764dd Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Thu, 8 Dec 2016 18:33:47 +0800 Subject: [PATCH 2/5] fix memory leaks fix memory leaks --- .../MMCardView/CardInfoView/CardCCell.swift | 1 - Example/MMCardView/SecondViewController.swift | 4 +-- Example/MMCardView/ViewController.swift | 5 ++-- MMCardView/Classes/CardCell.swift | 3 ++- MMCardView/Classes/CustomCardLayout.swift | 3 ++- MMCardView/Classes/CustomFlipTransition.swift | 26 +++++++++---------- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Example/MMCardView/CardInfoView/CardCCell.swift b/Example/MMCardView/CardInfoView/CardCCell.swift index 23e4885..1415adb 100644 --- a/Example/MMCardView/CardInfoView/CardCCell.swift +++ b/Example/MMCardView/CardInfoView/CardCCell.swift @@ -10,7 +10,6 @@ import UIKit import MMCardView class CardCCell: CardCell,CardCellProtocol { @IBOutlet weak var btnClick:UIButton! - private var callBack:(()->Void)? public static func cellIdentifier() -> String { return "CardC" } diff --git a/Example/MMCardView/SecondViewController.swift b/Example/MMCardView/SecondViewController.swift index a47e87f..9f74bb0 100644 --- a/Example/MMCardView/SecondViewController.swift +++ b/Example/MMCardView/SecondViewController.swift @@ -8,11 +8,11 @@ import UIKit -protocol SecondViewProtocol { +protocol SecondViewProtocol : class{ func removeCard() } class SecondViewController: UIViewController { - var delegate:SecondViewProtocol? + weak var delegate:SecondViewProtocol? override func viewDidLoad() { super.viewDidLoad() diff --git a/Example/MMCardView/ViewController.swift b/Example/MMCardView/ViewController.swift index f9a9e94..25f6b82 100644 --- a/Example/MMCardView/ViewController.swift +++ b/Example/MMCardView/ViewController.swift @@ -48,12 +48,13 @@ class ViewController: UIViewController,CardCollectionViewDataSource { let v = Int(arc4random_uniform(5))+1 c.imgV.image = UIImage.init(named: "image\(v)") case let c as CardCCell: - c.clickCallBack { + c.clickCallBack{ + [unowned self] in if let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Second") as? SecondViewController { vc.delegate = self self.card.presentViewController(to: vc) } - } + } default: return UICollectionViewCell() diff --git a/MMCardView/Classes/CardCell.swift b/MMCardView/Classes/CardCell.swift index 10ea42f..c65ffc1 100644 --- a/MMCardView/Classes/CardCell.swift +++ b/MMCardView/Classes/CardCell.swift @@ -13,8 +13,9 @@ public protocol CardCellProtocol { } open class CardCell:UICollectionViewCell{ - var collectionV:UICollectionView! + weak var collectionV:UICollectionView! var reloadBlock:(()->Void)? + public var callBack:(()->Void)? var customCardLayout:CardLayoutAttributes? var originTouchY:CGFloat = 0.0 var pangesture:UIPanGestureRecognizer? diff --git a/MMCardView/Classes/CustomCardLayout.swift b/MMCardView/Classes/CustomCardLayout.swift index 3a41648..729e6ca 100644 --- a/MMCardView/Classes/CustomCardLayout.swift +++ b/MMCardView/Classes/CustomCardLayout.swift @@ -56,7 +56,8 @@ class CustomCardLayout: UICollectionViewLayout { self.collectionView?.performBatchUpdates({ self.collectionView?.reloadData() }, completion: nil) - } get { + } + get { return _selectIdx } } diff --git a/MMCardView/Classes/CustomFlipTransition.swift b/MMCardView/Classes/CustomFlipTransition.swift index cd5fa4d..3b1c75a 100644 --- a/MMCardView/Classes/CustomFlipTransition.swift +++ b/MMCardView/Classes/CustomFlipTransition.swift @@ -15,14 +15,9 @@ enum TransitionMode: Int { public class CustomFlipTransition: NSObject,UIViewControllerAnimatedTransitioning { var duration = 0.3 var transitionMode:TransitionMode = .Present - var cardView:UICollectionViewCell! + weak var cardView:UICollectionViewCell! + weak var blurEffectView:UIVisualEffectView! var originalCardFrame = CGRect.zero - lazy var blurView:UIVisualEffectView = { - let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark) - let blurEffectView = UIVisualEffectView(effect: blurEffect) - blurEffectView.alpha = 0.0 - return blurEffectView - }() public func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { return duration @@ -41,15 +36,20 @@ public class CustomFlipTransition: NSObject,UIViewControllerAnimatedTransitionin toView?.frame = self.cardView.bounds toView?.layer.cornerRadius = viewRadius self.cardView.addSubview(toView!) - self.blurView.frame = containerView.bounds - self.blurView.alpha = 0.0 - containerView.addSubview(self.blurView) + + let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark) + let blurView = UIVisualEffectView(effect: blurEffect) + self.blurEffectView = blurView; + + blurView.frame = containerView.bounds + blurView.alpha = 0.0 + containerView.addSubview(blurView) UIView.transition(with: self.cardView, duration: 0.7, options: [.transitionFlipFromRight,.curveEaseIn], animations: { self.cardView.frame = CGRect.init(x: self.originalCardFrame.origin.x, y: self.originalCardFrame.origin.y, width: toViewF.width, height: toViewF.height) }, completion: { (finish) in UIView.animate(withDuration: 0.2, animations: { - self.blurView.alpha = 1.0 + blurView.alpha = 1.0 }) toView?.frame = toViewF @@ -68,10 +68,10 @@ public class CustomFlipTransition: NSObject,UIViewControllerAnimatedTransitionin fromView?.frame = CGRect.init(x: fromView!.frame.origin.x, y: fromView!.frame.origin.y, width: self.originalCardFrame.width, height: self.originalCardFrame.height) content.frame = CGRect.init(x: fromView!.frame.origin.x, y: fromView!.frame.origin.y, width: self.originalCardFrame.width, height: self.originalCardFrame.height) self.cardView.frame = CGRect.init(x: 0, y: self.originalCardFrame.origin.y, width: self.originalCardFrame.width, height: self.originalCardFrame.height) - self.blurView.alpha = 0.0 + self.blurEffectView.alpha = 0.0 }, completion: { (finish) in - self.blurView.removeFromSuperview() + self.blurEffectView.removeFromSuperview() content.backgroundColor = originalCrolor content.removeFromSuperview() self.cardView.addSubview(content) From 0096a000cb92779843658e0d6cbebd161c475aea Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Sun, 18 Dec 2016 23:09:47 +0800 Subject: [PATCH 3/5] update update --- MMCardView/Classes/CustomCardLayout.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMCardView/Classes/CustomCardLayout.swift b/MMCardView/Classes/CustomCardLayout.swift index 95fd608..2a4cbfa 100644 --- a/MMCardView/Classes/CustomCardLayout.swift +++ b/MMCardView/Classes/CustomCardLayout.swift @@ -138,7 +138,7 @@ class CustomCardLayout: UICollectionViewLayout { currentFrame = CGRect(x: self.collectionView!.frame.origin.x, y: titleHeight * CGFloat(index), width: cellSize.width, height: cellSize.height) switch showStyle { case .cover: - if index <= shitIdx || index == 0{ + if index <= shitIdx && (index >= shitIdx-2) || index == 0{ attribute.frame = CGRect(x: currentFrame.origin.x, y: self.collectionView!.contentOffset.y, width: cellSize.width, height: cellSize.height) } else if index < shitIdx-2 { attribute.isHidden = true From 19ccc1de8a26e3451e15e7c66e56b880998b00cc Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Sun, 18 Dec 2016 23:14:22 +0800 Subject: [PATCH 4/5] revert code revert code --- Example/MMCardView/CardInfoView/CardCCell.swift | 1 + MMCardView/Classes/CardCell.swift | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/MMCardView/CardInfoView/CardCCell.swift b/Example/MMCardView/CardInfoView/CardCCell.swift index 1415adb..23e4885 100644 --- a/Example/MMCardView/CardInfoView/CardCCell.swift +++ b/Example/MMCardView/CardInfoView/CardCCell.swift @@ -10,6 +10,7 @@ import UIKit import MMCardView class CardCCell: CardCell,CardCellProtocol { @IBOutlet weak var btnClick:UIButton! + private var callBack:(()->Void)? public static func cellIdentifier() -> String { return "CardC" } diff --git a/MMCardView/Classes/CardCell.swift b/MMCardView/Classes/CardCell.swift index c65ffc1..3419cfc 100644 --- a/MMCardView/Classes/CardCell.swift +++ b/MMCardView/Classes/CardCell.swift @@ -15,7 +15,6 @@ public protocol CardCellProtocol { open class CardCell:UICollectionViewCell{ weak var collectionV:UICollectionView! var reloadBlock:(()->Void)? - public var callBack:(()->Void)? var customCardLayout:CardLayoutAttributes? var originTouchY:CGFloat = 0.0 var pangesture:UIPanGestureRecognizer? From 93d9d972d7c2051b79d729abbfe82640da40240c Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Mon, 19 Dec 2016 00:06:14 +0800 Subject: [PATCH 5/5] add frame calculate add frame calculate --- MMCardView/Classes/CustomCardLayout.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MMCardView/Classes/CustomCardLayout.swift b/MMCardView/Classes/CustomCardLayout.swift index 2a4cbfa..95a7fc0 100644 --- a/MMCardView/Classes/CustomCardLayout.swift +++ b/MMCardView/Classes/CustomCardLayout.swift @@ -142,6 +142,7 @@ class CustomCardLayout: UICollectionViewLayout { attribute.frame = CGRect(x: currentFrame.origin.x, y: self.collectionView!.contentOffset.y, width: cellSize.width, height: cellSize.height) } else if index < shitIdx-2 { attribute.isHidden = true + attribute.frame = CGRect(x: currentFrame.origin.x, y: self.collectionView!.contentOffset.y, width: cellSize.width, height: cellSize.height) }else { attribute.frame = currentFrame }