一个用于构建如 Tinder 和 Potluck 一样卡片界面的简单视图。ZLSwipeableView 最初是为 Murmur 开发的。
注意: ZLSwipeableView 的 Objective-C 版本不再维护。
查看 示例应用程序 以获取示例。
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];
ZLSwipeableView 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。