diff --git a/README.md b/README.md index 4c6b2aa..b284492 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,30 @@ ZLSwipeableView *swipeableView = [[ZLSwipeableView alloc] initWithFrame:self.vie 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. ~~~objective-c +// 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. +~~~objective-c +// 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: ~~~objective-c diff --git a/ZLSwipeableViewDemo/ZLSwipeableViewDemo/Base.lproj/Main.storyboard b/ZLSwipeableViewDemo/ZLSwipeableViewDemo/Base.lproj/Main.storyboard index bbd4ed5..f5f2eb9 100644 --- a/ZLSwipeableViewDemo/ZLSwipeableViewDemo/Base.lproj/Main.storyboard +++ b/ZLSwipeableViewDemo/ZLSwipeableViewDemo/Base.lproj/Main.storyboard @@ -27,7 +27,7 @@ - + @@ -64,7 +64,7 @@ - + diff --git a/ZLSwipeableViewDemo/ZLSwipeableViewDemo/ViewController.m b/ZLSwipeableViewDemo/ZLSwipeableViewDemo/ViewController.m index 4820f7e..7fff861 100644 --- a/ZLSwipeableViewDemo/ZLSwipeableViewDemo/ViewController.m +++ b/ZLSwipeableViewDemo/ZLSwipeableViewDemo/ViewController.m @@ -11,7 +11,7 @@ #import "UIColor+FlatColors.h" #import "CardView.h" -@interface ViewController () +@interface ViewController () @property (weak, nonatomic) IBOutlet ZLSwipeableView *swipeableView; @property (nonatomic, strong) NSArray *colors; @@ -47,12 +47,17 @@ - (void)viewDidLoad { @"Asbestos", ]; -// ZLSwipeableContainterView *container = [[ZLSwipeableContainterView alloc] initWithFrame:self.view.frame]; -// [self.view addSubview:container]; + // ZLSwipeableView *swipeableView = [[ZLSwipeableView alloc] initWithFrame:self.view.frame]; + // [self.view addSubview:swipeableView]; [self.swipeableView setNeedsLayout]; [self.swipeableView layoutIfNeeded]; + + // required data source self.swipeableView.dataSource = self; + + // optional delegate + self.swipeableView.delegate = self; } - (IBAction)swipeLeftButtonAction:(UIButton *)sender { [self.swipeableView swipeTopViewToLeft]; @@ -66,6 +71,18 @@ - (IBAction)reloadButtonAction:(UIButton *)sender { [self.swipeableView loadNextSwipeableViewsIfNeeded]; } +#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); +} + +#pragma mark - ZLSwipeableViewDataSource - (UIView *)nextViewForSwipeableView:(ZLSwipeableView *)swipeableView { if (self.colorIndex +@protocol ZLSwipeableViewDelegate @optional - - (void)swipeableView: (ZLSwipeableView *)swipeableView didSwipeLeft:(UIView *)view; - (void)swipeableView: (ZLSwipeableView *)swipeableView didSwipeRight:(UIView *)view; - +- (void)swipeableView: (ZLSwipeableView *)swipeableView swipingView:(UIView *)view atLocation:(CGPoint)location; @end @@ -28,7 +27,7 @@ @interface ZLSwipeableView : UIView @property (nonatomic, weak) id dataSource; -@property (nonatomic, weak) id delegate; +@property (nonatomic, weak) id delegate; /** * Enable this to rotate the views behind the top view. Default to YES. diff --git a/ZLSwipeableViewDemo/ZLSwipeableViewDemo/ZLSwipeableView/ZLSwipeableView.m b/ZLSwipeableViewDemo/ZLSwipeableViewDemo/ZLSwipeableView/ZLSwipeableView.m index 52be4bf..5ba6066 100644 --- a/ZLSwipeableViewDemo/ZLSwipeableViewDemo/ZLSwipeableView/ZLSwipeableView.m +++ b/ZLSwipeableViewDemo/ZLSwipeableViewDemo/ZLSwipeableView/ZLSwipeableView.m @@ -30,7 +30,7 @@ @interface ZLSwipeableView ()