iOS实现的类似Tinder卡片界面:ZLSwipeableViewSwift

jopen 9年前

ZLSwipeableViewSwift 是一个简单的视图,可以建立类似 Tinder 和 Potluck 的卡片界面,使用 Swift 写成的。

用法

Check out the demo app for an example. It contains the following demos: Default, Custom Animation, Custom Swipe, Custom Direction and Undo.

ZLSwipeableViewcan be added to storyboard or instantiated programmatically:

var swipeableView = ZLSwipeableView(frame: CGRect(x: 0, y: 0, width: 300, height: 500)))  view.addSubview(swipeableView)

ThenextViewproperty, a closure that returns anUIView, is used to provide subviews toZLSwipeableView. After defining it, you can callloadViewsandZLSwipeableViewwill invokenextViewnumPrefetchedViewstimes and animate the prefetched views.

swipeableView.nextView = { return UIView()  }  swipeableView.numPrefetchedViews = 3 swipeableView.loadViews()

The demo app includes examples of both creating views programmatically and loading views from Xib files that use Auto Layout.

To discard all views and reload programmatically:

swipeableView.discardViews()  swipeableView.loadViews()

You can limit the direction swiping happens using thedirectionproperty and register callbacks like this. Take a look at the Custom Direction example for details.

swipeableView.direction = .Left | .Up  swipeableView.direction = .All    swipeableView.didStart = {view, location in      println("Did start swiping view at location: \(location)")  }  swipeableView.swiping = {view, location, translation in      println("Swiping at view location: \(location) translation: \(translation)")  }  swipeableView.didEnd = {view, location in      println("Did end swiping view at location: \(location)")  }  swipeableView.didSwipe = {view, direction, vector in      println("Did swipe view in direction: \(direction), vector: \(vector)")  }  swipeableView.didCancel = {view in      println("Did cancel swiping view")  }

iOS实现的类似Tinder卡片界面:ZLSwipeableViewSwift

项目主页:http://www.open-open.com/lib/view/home/1433901259926