可滑动删除的垂直卡片 - VerticalCardSwitcher

2017-05-20      22      Swift
项目简介

VerticalCardSwitcher

VerticalCardSwitcheris inspired by Shazam Discover view. It is a vertical sequence ofUIViews where firstUIViewin sequence is always completely displayed and every nextUIViewis partially displayed. Also there isVerticalCardSwitcherDelegatewhich is added forVerticalCardSwitchercustomization.VerticalCardSwitcheris not implemented withUICollectionViewand it's contained inside parent view.

Example

To run the example project, clone the repo, and runpod installfrom the Example directory first. There are two examplesFirstViewControllerandSecondViewController.

  • Example 1 (FirstViewController):

  • Example 2 (SecondViewController):

Requirements

  • iOS 8.0+
  • Xcode 8
  • Swift 3.0

Installation

VerticalCardSwitcher is available through CocoaPods . To install it, simply add the following lines to your Podfile:

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
    pod "VerticalCardSwitcher"
end

Usage

  1. AddVerticalCardSwitcherDelegatefor delegate class:
class ViewController: UIViewController, VerticalCardSwitcherDelegate {

}
  1. Initialize and setupVerticalCardSwitcher:
private var verticalCardSwitcher: VerticalCardSwitcher!

verticalCardSwitcher = VerticalCardSwitcher.init(in: view)
verticalCardSwitcher.delegate = self
verticalCardSwitcher.display()
  1. ImplementVerticalCardSwitcherDelegaterequired methods:
func numberOfCards(for verticalCardSwitcher: VerticalCardSwitcher) -> Int {
    return 22
}

func distanceBetweenCards(for verticalCardSwitcher: VerticalCardSwitcher) -> CGFloat {
    return 20.0
}

func heightForCardView(in verticalCardSwitcher: VerticalCardSwitcher) -> CGFloat {
    return 430.0
}

func sideMargins(for verticalCardSwitcher: VerticalCardSwitcher) -> CGFloat {
    return 40.0
}

func addDesign(for cardView: CardView, at index: Int, in verticalCardSwitcher: VerticalCardSwitcher) {

}

// values from 0 to 1 (represents percentage of CardView height)
func heightOfShowedPartForEveryNextCard(in verticalCardSwitcher: VerticalCardSwitcher) -> CGFloat {
    return 0.20
}
  1. ImplementVerticalCardSwitcherDelegateoptional methods for scrolling events of CardView:
func currentCardScrolledDown(cardView: CardView, for verticalCardSwitcher: VerticalCardSwitcher) {
    print("currentCardScrolledDown")
}

func nextCardScrolledUp(cardView: CardView, for verticalCardSwitcher: VerticalCardSwitcher) {
    print("nextCardScrolledUp")
}