Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxnlai committed Oct 24, 2015
1 parent 6f84365 commit 1a62139
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
8 changes: 1 addition & 7 deletions ZLSwipeableView/ZLSwipeableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,11 @@ typedef NS_ENUM(NSUInteger, ZLSwipeableViewDirection) {
@property (nonatomic) CGFloat escapeVelocityThreshold;

/// The relative distance from center that will
@property (nonatomic) CGFloat relativeDisplacementThreshold;
@property (nonatomic) CGFloat relativeTranslationThreshold;

/// Magnitude of velocity at which the swiped view will be animated.
@property (nonatomic) CGFloat pushVelocityMagnitude;

/// Center of swipable Views. This property is animated.
@property (nonatomic) CGPoint swipeableViewsCenter;

/// Center of swipable Views. This property is animated.
@property (nonatomic) CGPoint swipeableViewsCenterInitial;

/// Swiped views will be destroyed when they collide with this rect.
@property (nonatomic) CGRect collisionRect;

Expand Down
41 changes: 16 additions & 25 deletions ZLSwipeableView/ZLSwipeableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,9 @@ - (void)setup {
self.direction = ZLSwipeableViewDirectionAll;
self.pushVelocityMagnitude = 1000;
self.escapeVelocityThreshold = 750;
self.relativeDisplacementThreshold = 0.25;
self.relativeTranslationThreshold = 0.25;

self.programaticSwipeRotationRelativeYOffsetFromCenter = -0.2;
self.swipeableViewsCenter =
CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
self.swipeableViewsCenterInitial =
CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
self.collisionRect = [self defaultCollisionRect];
}

Expand All @@ -108,18 +104,6 @@ - (void)layoutSubviews {
self.anchorContainerView.frame = CGRectMake(0, 0, 1, 1);
self.containerView.frame = self.bounds;
self.reuseCoverContainerView.frame = self.bounds;
self.swipeableViewsCenterInitial = CGPointMake(
self.bounds.size.width / 2 + self.swipeableViewsCenterInitial.x -
self.swipeableViewsCenter.x,
self.bounds.size.height / 2 + self.swipeableViewsCenterInitial.y -
self.swipeableViewsCenter.y);
self.swipeableViewsCenter =
CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
}

- (void)setSwipeableViewsCenter:(CGPoint)swipeableViewsCenter {
_swipeableViewsCenter = swipeableViewsCenter;
[self animateSwipeableViewsIfNeeded];
}

#pragma mark - Properties
Expand All @@ -146,7 +130,8 @@ - (void)loadNextSwipeableViewsIfNeeded {
if (nextView) {
[self.containerView addSubview:nextView];
[self.containerView sendSubviewToBack:nextView];
nextView.center = self.swipeableViewsCenterInitial;
nextView.center =
[self convertPoint:self.center fromView:self.superview];
[newViews addObject:nextView];
}
}
Expand Down Expand Up @@ -180,7 +165,8 @@ - (void)animateSwipeableViewsIfNeeded {
self.swipeableViewSnapBehavior = [self
snapBehaviorThatSnapView:self.containerView
.subviews[numSwipeableViews - 1]
toPoint:self.swipeableViewsCenter];
toPoint:[self convertPoint:self.center
fromView:self.superview]];
[self.animator addBehavior:self.swipeableViewSnapBehavior];
}
CGPoint rotationCenterOffset = {
Expand Down Expand Up @@ -253,7 +239,7 @@ - (void)handlePan:(UIPanGestureRecognizer *)recognizer {

if ((ZLDirectionVectorToSwipeableViewDirection(directionVector) &
self.direction) > 0 &&
(ABS(translation.x) > self.relativeDisplacementThreshold *
(ABS(translation.x) > self.relativeTranslationThreshold *
self.bounds.size.width || // displacement
velocityMagnitude > self.escapeVelocityThreshold) && // velocity
(signum(translation.x) == signum(normalizedVelocity.x)) && // sign X
Expand All @@ -267,9 +253,10 @@ - (void)handlePan:(UIPanGestureRecognizer *)recognizer {
[self.animator removeBehavior:self.anchorViewAttachmentBehavior];

[self.anchorView removeFromSuperview];
self.swipeableViewSnapBehavior =
[self snapBehaviorThatSnapView:swipeableView
toPoint:self.swipeableViewsCenter];
self.swipeableViewSnapBehavior = [self
snapBehaviorThatSnapView:swipeableView
toPoint:[self convertPoint:self.center
fromView:self.superview]];
[self.animator addBehavior:self.swipeableViewSnapBehavior];

if ([self.delegate respondsToSelector:@selector(swipeableView:
Expand Down Expand Up @@ -568,16 +555,20 @@ - (void)rotateView:(UIView *)view
float duration = animated ? 0.4 : 0;
float rotationRadian = [self degreesToRadians:degree];
[UIView animateWithDuration:duration
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
view.center = self.swipeableViewsCenter;
view.center = [self convertPoint:self.center
fromView:self.superview];
CGAffineTransform transform =
CGAffineTransformMakeTranslation(offset.x, offset.y);
transform =
CGAffineTransformRotate(transform, rotationRadian);
transform = CGAffineTransformTranslate(
transform, -offset.x, -offset.y);
view.transform = transform;
}];
}
completion:nil];
}

- (UIView *)topSwipeableView {
Expand Down
4 changes: 2 additions & 2 deletions ZLSwipeableViewDemo/ZLSwipeableViewDemo/CardContentView.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="14C81f" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand Down

0 comments on commit 1a62139

Please sign in to comment.