测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最新版本 | 2016年7月 |
SPM支持 SPM | ✗ |
由 George Kye,George Kye 维护。
依赖项 | |
Stellar | >= 0 |
PeekView | >= 0 |
用于创建类似 Tinder 的 swipe 卡的一种 UIView 子类,带有 peek 视图。
Swiper 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中
pod 'Swiper'
查看示例应用程序以获取详细的示例。
可以通过 storyboard 或编程方式添加 Swiper
视图。
var swiperView = Swiper(frame: CGRect(x: 0, y: 0, width: 350, height: 350)))
view.addSubview(swiperView)
swipeView.delegate = self
swipeView.dataSource = self
返回在 Swiper
视图中显示的图像。
public func cardData() -> [SwiperData]
返回 Swiper
视图显示的项目数量。
public func numberOfCards()->Int
当 Swiper
视图首次显示或每次发生 swipe 动作时调用该方法。返回卡片当前索引及其 dataSource
。
public func didShowCardAtIndex(index: Int, dataSource: SwiperData)
当 Swiper
视图向左滑动或通过程序调用 undoSwipe
时调用该方法。返回卡片当前索引及其 dataSource。
public func didUndoAction(index: Int, dataSource: SwiperData)
当 Swiper
视图被点击时调用该方法。返回当前项目的卡片当前索引
public func didSelectCardAtIndex(index: Int)
当 Swiper
视图没有更多的项目可以显示时调用该方法
public func cardsDidRunOut(status: Bool)
Swiper 支持左右滑动操作。使用 Swiper Right
进入下一张卡片,使用 Swipe left
撤销操作。这些操作也支持通过程序执行。
public func swipeToNext()
public func undoSwipe()
从当前 dataSource
中重新加载 Swiper
视图的项目并刷新显示。
public func reloadData()
要使用 PeekView
,必须将 peekViewEnabed = true
并符合 peekViewDelegate
。
swipeView.peekViewEnabled = true
swipeView.peekViewDelegate = self
为了使 peekView 能够运行,必须设置 parentViewController
和 contentViewController
(actions
是可选的)。下面是一个示例。
func swiperPeekViewAttributes() -> SwiperPeekViewAttributes {
let controller = storyboard?.instantiateViewControllerWithIdentifier("PeekViewController") as! PeekViewController
controller.image = imgs[currentIndex].image
controller.labelText = imgs[currentIndex].title
let actions = [
PeekViewAction(title: "Like", style: .Selected),
PeekViewAction(title: "Show Details", style: .Default),
PeekViewAction(title: "Cancel", style: .Destructive) ]
let attributes = SwiperPeekViewAttributes.init(parentVC: self, contentVC: controller, actions: actions)
return attributes
}
返回从 PeekView
中选择的动作的索引。
func swiperPeekViewDidSelectAtionAtIndex(index: Int)
Swiper 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。