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..3419cfc 100644 --- a/MMCardView/Classes/CardCell.swift +++ b/MMCardView/Classes/CardCell.swift @@ -13,7 +13,7 @@ public protocol CardCellProtocol { } open class CardCell:UICollectionViewCell{ - var collectionV:UICollectionView! + weak var collectionV:UICollectionView! var reloadBlock:(()->Void)? var customCardLayout:CardLayoutAttributes? var originTouchY:CGFloat = 0.0 diff --git a/MMCardView/Classes/CustomCardLayout.swift b/MMCardView/Classes/CustomCardLayout.swift index a7a2d3a..95a7fc0 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 } } @@ -141,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 } 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)