iOS實現的類似Tinder卡片界面:ZLSwipeableViewSwift

jopen 9年前發布 | 20K 次閱讀 iOS開發 移動開發 ZLSwipeableViewSwift

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.baiduhome.net/lib/view/home/1433901259926

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!