mejasonwang / ZLSwipeableView

A simple view for building card like interface like Tinder and Potluck.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZLSwipeableView

A simple view for building card like interface like Tinder and Potluck.

Preview

###Swipe swipe ###Swipe Cancel cancel ###Swipe Programmatically swipeLeft

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).

License

ZLSwipeableView is available under MIT license. See the LICENSE file for more info.

About

A simple view for building card like interface like Tinder and Potluck.

License:MIT License