ZLSwipeableView 0.0.8

ZLSwipeableView 0.0.8

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2015 年 10 月

Zhixuan Lai 维护。




  • Zhixuan Lai

一个用于构建如 TinderPotluck 一样卡片界面的简单视图。ZLSwipeableView 最初是为 Murmur 开发的。

注意: ZLSwipeableView 的 Objective-C 版本不再维护。

请检查 swift 版本: https://github.com/zhxnlai/ZLSwipeableViewSwift

预览

滑动

swipe

滑动取消

cancel

程序滑动

swipeLeft

程序滑动 II

swipeLeftRight

用法

查看 示例应用程序 以获取示例。

ZLSwipeableView 可以添加到 Storyboard 中或通过程序实例化

ZLSwipeableView *swipeableView = [[ZLSwipeableView alloc] initWithFrame:self.view.frame];
[self.view addSubview:swipeableView];

ZLSwipeableView 必须 有一个实现了 ZLSwipeableViewDataSource 的对象,作为数据源。 开启将预取 三个 视图,以进行动画处理。

// required data source
self.swipeableView.dataSource = self;

#pragma mark - ZLSwipeableViewDataSource
- (UIView *)nextViewForSwipeableView:(ZLSwipeableView *)swipeableView {
  return [[UIView alloc] init];
}

示例应用程序包含了创建视图的程序示例和从 Xib 文件加载视图的例子,该文件使用 自动布局

ZLSwipeableView 可以有一个可选的代理来接收回调。

// optional delegate
self.swipeableView.delegate = self;

#pragma mark - ZLSwipeableViewDelegate
- (void)swipeableView:(ZLSwipeableView *)swipeableView
         didSwipeView:(UIView *)view
          inDirection:(ZLSwipeableViewDirection)direction {
    NSLog(@"did swipe in direction: %zd", direction);
}
- (void)swipeableView:(ZLSwipeableView *)swipeableView didCancelSwipe:(UIView *)view {
  NSLog(@"did cancel swipe");
}
- (void)swipeableView:(ZLSwipeableView *)swipeableView didStartSwipingView:(UIView *)view atLocation:(CGPoint)location {
    NSLog(@"did start swiping at location: x %f, y%f", location.x, location.y);
}
- (void)swipeableView:(ZLSwipeableView *)swipeableView swipingView:(UIView *)view atLocation:(CGPoint)location  translation:(CGPoint)translation {
    NSLog(@"swiping at location: x %f, y %f, translation: x %f, y %f", location.x, location.y, translation.x, translation.y);
}
- (void)swipeableView:(ZLSwipeableView *)swipeableView didEndSwipingView:(UIView *)view atLocation:(CGPoint)location {
    NSLog(@"did start swiping at location: x %f, y%f", location.x, location.y);
}

要程序滑动顶部视图

[self.swipeableView swipeTopViewToLeft];
[self.swipeableView swipeTopViewToRight];
...

要丢弃所有视图并重新加载

[self.swipeableView discardAllSwipeableViews];
[self.swipeableView loadNextSwipeableViewsIfNeeded];

要求

  • iOS 7 或更高版本。
  • 自动引用计数 (ARC)。

鸣谢

  • 感谢 iamphill 添加了新的代理。
  • 感谢 mdznr 使代码风格保持一致。
  • 感谢 coryalder 使数据源和代理 IB Outlets。

许可证

ZLSwipeableView 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。