類似于Tinder卡片的iOS庫:ZLSwipeableView

jopen 11年前發布 | 29K 次閱讀 iOS開發 移動開發 ZLSwipeableView

一個簡單的視圖用于構建類似 Tinder and Potluck的卡片界面。

Preview

Swipe

類似于Tinder卡片的iOS庫:ZLSwipeableView

Swipe Cancel

類似于Tinder卡片的iOS庫:ZLSwipeableView

Swipe Programmatically

類似于Tinder卡片的iOS庫:ZLSwipeableView

CocoaPods

You can install ZLSwipeableView through CocoaPods adding the following to your Podfile:

pod 'ZLSwipeableView'

Usage

Check out the demo app for an example.

ZLSwipeableView can be added to storyboard or initialized programmatically:

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

A ZLSwipeableView must have an object that implements ZLSwipeableViewDelegate to act as a data source. ZLSwipeableView will prefetch three views in advance to animate them.

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

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

A ZLSwipeableView can have an optional delegate to receive callback.

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

#pragma mark - ZLSwipeableViewDelegate
- (void)swipeableView: (ZLSwipeableView *)swipeableView didSwipeLeft:(UIView *)view {
    NSLog(@"did swipe left");
}
- (void)swipeableView: (ZLSwipeableView *)swipeableView didSwipeRight:(UIView *)view {
    NSLog(@"did swipe right");
}
- (void)swipeableView: (ZLSwipeableView *)swipeableView swipingView:(UIView *)view atLocation:(CGPoint)location {
    NSLog(@"swiping at location: x %f, y%f", location.x, location.y);
}

To swipe the top view programmatically:

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

To discard all views and reload programmatically:

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

Requirements

  • iOS 7 or higher.
  • Automatic Reference Counting (ARC).

項目主頁:http://www.baiduhome.net/lib/view/home/1415068583669

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