1. cardViewMode
    • remove scroll in UIPageViewController
  2. LinkedList
  3. CABasicAnimation
  4. fix a bug with a trick


add init function in customUIPageViewController

    // custom initializer
    init(isCardViewMode: Bool = false) {
        self.isCardViewMode = isCardViewMode
        super.init(transitionStyle: .scroll, navigationOrientation: .horizontal)

How to remove scroll in UIPageViewController

we don’t need a scroll function in CardView, only need it in UserDetailViewController. So all we need to do is setting each subview’s isScrollEnabled on false

    fileprivate func disableSwipingAbility() {
        view.subviews.forEach { (v) in
            if let v = v as? UIScrollView {
                v.isScrollEnabled = false

LinkedList in CardView

// in CardView.swift
    var nextCardView

set nextCardView when fetch Users from firestore

// in HomeController.swift
// fetchUsersFromFirestore()
            var previousCardView: CardView?

            snapshot?.documents.forEach({ (documentSnapshot) in
                let userDictionary = documentSnapshot.data()
                let user = User(dictionary: userDictionary)
                if user.uid != Auth.auth().currentUser?.uid {
                    let cardView = self.setupCardFromUser(user: user)
                    previousCardView?.nextCardView = cardView
                    previousCardView = cardView
                    if self.topCardView == nil {
                        self.topCardView = cardView

Synchronize likeButton swiping - actual swiping

use delegate of CardView

We have already specified protocol CardViewDelegate, didTapMoreInfo between CardView and HomeController

specify didRemoveCard(cardView: CardView) in CardViewDelegate

protocol CardViewDelegate {
    func didTapMoreInfo(cardViewModel: CardViewModel)
    func didRemoveCard(cardView: CardView)

call didRemoveCard on Completing swiping a cardView

self.delegate?.didRemoveCard(cardView: self)

Change animation type to fix bug

create an animation with CABasicAnimation(), watch out a keypath!

    fileprivate func performSwipeAnimation(traslation: CGFloat, angle: CGFloat) {
        let duration = 0.5
        let translationAnimation = CABasicAnimation(keyPath: "position.x")
        translationAnimation.toValue = traslation
        translationAnimation.duration = duration
        translationAnimation.fillMode = .forwards
        translationAnimation.timingFunction = CAMediaTimingFunction(name: .easeOut)
        translationAnimation.isRemovedOnCompletion = false
        let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
        rotationAnimation.toValue = angle * CGFloat.pi / 180
        rotationAnimation.duration = duration
        CATransaction.setCompletionBlock {
        topCardView?.layer.add(translationAnimation, forKey: "translation")
        topCardView?.layer.add(rotationAnimation, forKey: "rotation")
  • CATransaction.setCompletionBlock

  • layer.add()

  • CATransaction.commit

fix: tap likeButton rapidly

we need a trick

change topCardView to nextCardView tapping a button

        let cardView = topCardView
        topCardView = cardView?.nextCardView
        CATransaction.setCompletionBlock {
        cardView?.layer.add(translationAnimation, forKey: "translation")
        cardView?.layer.add(rotationAnimation, forKey: "rotation")

Refactoring by toValue

save in settingsController bug

set topCardView as nil in fetchUsersFromFirestore()

태그: ,