Skip to content

Commit

Permalink
Simplify didSwipeView delegate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
zen committed Feb 5, 2015
1 parent 449d7e1 commit 2041dc7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
14 changes: 3 additions & 11 deletions ZLSwipeableView/ZLSwipeableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,10 @@ typedef NS_ENUM(NSUInteger, ZLSwipeableViewDirection) {

/// Delegate
@protocol ZLSwipeableViewDelegate <NSObject>

- (void)swipeableView:(ZLSwipeableView *)swipeableView
didSwipeUp:(UIView *)view;

- (void)swipeableView:(ZLSwipeableView *)swipeableView
didSwipeDown:(UIView *)view;

- (void)swipeableView:(ZLSwipeableView *)swipeableView
didSwipeLeft:(UIView *)view;

@optional
- (void)swipeableView:(ZLSwipeableView *)swipeableView
didSwipeRight:(UIView *)view;
didSwipeView:(UIView *)view
inDirection:(ZLSwipeableViewDirection)direction;

- (void)swipeableView:(ZLSwipeableView *)swipeableView
didCancelSwipe:(UIView *)view;
Expand Down
37 changes: 16 additions & 21 deletions ZLSwipeableView/ZLSwipeableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -461,33 +461,28 @@ - (void)createAnchorViewForCover:(UIView *)swipeableView
}

- (void)pushAnchorViewForCover:(UIView *)swipeableView
inDirection:(CGVector)direction
inDirection:(CGVector)directionVector
andCollideInRect:(CGRect)collisionRect {
if (ABS(direction.dx) > ABS(direction.dy)) {
if (direction.dx > 0) {
if (self.delegate &&
[self.delegate
respondsToSelector:@selector(swipeableView:didSwipeRight:)])
[self.delegate swipeableView:self didSwipeRight:swipeableView];
ZLSwipeableViewDirection direction = ZLSwipeableViewDirectionNone;

if (ABS(directionVector.dx) > ABS(directionVector.dy)) {
if (directionVector.dx > 0) {
direction = ZLSwipeableViewDirectionRight;
} else {
if (self.delegate &&
[self.delegate
respondsToSelector:@selector(swipeableView:didSwipeLeft:)])
[self.delegate swipeableView:self didSwipeLeft:swipeableView];
direction = ZLSwipeableViewDirectionLeft;
}
} else {
if (direction.dy > 0) {
if (self.delegate &&
[self.delegate
respondsToSelector:@selector(swipeableView:didSwipeDown:)])
[self.delegate swipeableView:self didSwipeDown:swipeableView];
if (directionVector.dy > 0) {
direction = ZLSwipeableViewDirectionDown;
} else {
if (self.delegate &&
[self.delegate
respondsToSelector:@selector(swipeableView:didSwipeUp:)])
[self.delegate swipeableView:self didSwipeUp:swipeableView];
direction = ZLSwipeableViewDirectionUp;
}
}

if ([self.delegate respondsToSelector:@selector(swipeableView:didSwipeView:inDirection:)]) {
[self.delegate swipeableView:self didSwipeView:swipeableView inDirection:direction];
}

[self.animator removeBehavior:self.anchorViewAttachmentBehavior];

UICollisionBehavior *collisionBehavior =
Expand All @@ -497,7 +492,7 @@ - (void)pushAnchorViewForCover:(UIView *)swipeableView
[self.animator addBehavior:collisionBehavior];

UIPushBehavior *pushBehavior =
[self pushBehaviorThatPushView:self.anchorView toDirection:direction];
[self pushBehaviorThatPushView:self.anchorView toDirection:directionVector];
[self.animator addBehavior:pushBehavior];

[self.reuseCoverContainerView addSubview:self.anchorView];
Expand Down

0 comments on commit 2041dc7

Please sign in to comment.