Skip to content

Commit

Permalink
边缘手势调整
Browse files Browse the repository at this point in the history
  • Loading branch information
ChavezChen committed Jan 3, 2019
1 parent 441ea5b commit 96b3b3f
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 39 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions CWLateralSlide.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "CWLateralSlide"
s.version = "1.6.3"
s.version = "1.6.4"
s.summary = "侧滑抽屉框架."

s.description = "一行代码集成侧滑抽屉功能."
Expand Down Expand Up @@ -74,7 +74,7 @@ Pod::Spec.new do |s|
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/ChavezChen/CWLateralSlide.git", :tag => "1.6.3" }
s.source = { :git => "https://github.com/ChavezChen/CWLateralSlide.git", :tag => "1.6.4" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
Expand Down
88 changes: 66 additions & 22 deletions CWLateralSlide/CWInteractiveTransition.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,23 @@ + (instancetype)interactiveWithTransitiontype:(CWDrawerTransitiontype)type {
- (void)addPanGestureForViewController:(UIViewController *)viewController {

self.weakVC = viewController;
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(cw_handleShowPan:)];
pan.delegate = self;
[viewController.view addGestureRecognizer:pan];
if (self.openEdgeGesture) {
// 因为edges设置为(UIRectEdgeLeft | UIRectEdgeLeft)或者 UIRectEdgeAll都无效,所以增加左右两个边缘手势
UIScreenEdgePanGestureRecognizer *edgePanFromLeft = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(cw_handleEdgePan:)];
edgePanFromLeft.edges = UIRectEdgeLeft;
edgePanFromLeft.delegate = self;
[viewController.view addGestureRecognizer:edgePanFromLeft];

UIScreenEdgePanGestureRecognizer *edgePanFromRight = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(cw_handleEdgePan:)];
edgePanFromRight.edges = UIRectEdgeRight;
edgePanFromRight.delegate = self;
[viewController.view addGestureRecognizer:edgePanFromRight];

}else {
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(cw_handleShowPan:)];
pan.delegate = self;
[viewController.view addGestureRecognizer:pan];
}
}

- (UIViewController *)viewController:(UIView *)view{
Expand Down Expand Up @@ -100,20 +114,25 @@ - (void)showBeganTranslationX:(CGFloat)x gesture:(UIPanGestureRecognizer *)pan {
if ((x < 0 && _direction == CWDrawerTransitionFromLeft) ||
(x > 0 && _direction == CWDrawerTransitionFromRight)) return;

CGFloat locX = [pan locationInView:_weakVC.view].x;
// NSLog(@"locX: %f",locX);
if (_openEdgeGesture && ((locX > 50 && _direction == CWDrawerTransitionFromLeft) || (locX < CGRectGetWidth(_weakVC.view.frame) - 50 && _direction == CWDrawerTransitionFromRight))) return;

self.interacting = YES;
if (_transitionDirectionAutoBlock) {
_transitionDirectionAutoBlock(_direction);
}
}

- (void)cw_updateInteractiveTransition {
_percent = fminf(fmaxf(_percent, 0.003), 0.97);
[self updateInteractiveTransition:_percent];
}

- (void)cw_endInteractiveTransition {
self.interacting = NO;
[self startTimerAnimationWithFinishTransition:_percent > self.configuration.finishPercent];
}

- (void)handleGesture:(UIPanGestureRecognizer *)pan {

CGFloat x = [pan translationInView:pan.view].x;

_percent = 0;
_percent = x / pan.view.frame.size.width;

Expand All @@ -133,40 +152,65 @@ - (void)handleGesture:(UIPanGestureRecognizer *)pan {
[self hiddenBeganTranslationX:x];
}
}else {
_percent = fminf(fmaxf(_percent, 0.003), 0.97);
[self updateInteractiveTransition:_percent];
[self cw_updateInteractiveTransition];
}
break;
}
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateEnded:{
[self cw_endInteractiveTransition];
break;
}
default:
break;
}
}

self.interacting = NO;
if (_percent > self.configuration.finishPercent) {
[self startDisplayerLink:_percent toFinish:YES];
}else {
[self startDisplayerLink:_percent toFinish:NO];
#pragma mark edge gesture
- (void)cw_handleEdgePan:(UIScreenEdgePanGestureRecognizer *)edgePan {
if (_type == CWDrawerTransitiontypeHidden) return;

CGFloat x = [edgePan translationInView:edgePan.view].x;
_percent = 0;
_percent = x / edgePan.view.frame.size.width;
_direction = edgePan.edges == UIRectEdgeRight;
if (_direction == CWDrawerTransitionFromRight) {
_percent = -_percent;
}
switch (edgePan.state) {
case UIGestureRecognizerStateBegan: {
self.interacting = YES;
if (_transitionDirectionAutoBlock) {
_transitionDirectionAutoBlock(_direction);
}
break;
}
case UIGestureRecognizerStateChanged: {
[self cw_updateInteractiveTransition];
break;
}
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateEnded:{
[self cw_endInteractiveTransition];
break;
}
default:
break;
}
}


- (void)startDisplayerLink:(CGFloat)percent toFinish:(BOOL)finish{
if (finish && percent >= 1) {
- (void)startTimerAnimationWithFinishTransition:(BOOL)isFinish {
if (isFinish && _percent >= 1) {
[self finishInteractiveTransition];
return;
}else if (!finish && percent <= 0) {
}else if (!isFinish && _percent <= 0) {
[self cancelInteractiveTransition];
return;
}
_toFinish = finish;
CGFloat remainDuration = finish ? self.duration * (1 - percent) : self.duration * percent;
_toFinish = isFinish;
CGFloat remainDuration = isFinish ? self.duration * (1 - _percent) : self.duration * _percent;
_remaincount = 60 * remainDuration;
_oncePercent = finish ? (1 - percent) / _remaincount : percent / _remaincount;
_oncePercent = isFinish ? (1 - _percent) / _remaincount : _percent / _remaincount;
[self starDisplayLink];
}

Expand Down
19 changes: 11 additions & 8 deletions CWLateralSlide/UIViewController+CWLateralSlide.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
//
// Created by chavez on 2017/6/29.
// Copyright © 2017年 chavez. All rights reserved.
// v1.4.2
// v1.6.4

#import <UIKit/UIKit.h>
#import "CWLateralSlideAnimator.h"
#import "CWLateralSlideConfiguration.h"

@interface UIViewController (CWLateralSlide)

/*-----------------------------------v1.6.3-----------------------------------------*/
/*-----------------------------------v1.6.3-----------------------------------------*/
/*-----------------------------------v1.6.3-----------------------------------------*/
/*-----------------------------------v1.6.4-----------------------------------------*/
/*-----------------------------------v1.6.4-----------------------------------------*/
/*-----------------------------------v1.6.4-----------------------------------------*/

/**
显示默认抽屉
Expand All @@ -37,10 +37,11 @@
/**
注册手势驱动方法,侧滑呼出的方向自动确定,一般在viewDidLoad调用,调用之后会添加一个支持侧滑的手势到本控制器
@param openEdgeGesture 是否开启边缘手势,边缘手势的开始范围为距离边缘50以内
@param openEdgeGesture 是否开启边缘手势,系统的边缘手势判断
@param transitionDirectionAutoBlock 手势过程中执行的操作。根据参数direction传整个点击present的事件即可(看demo的使用)
*/
- (void)cw_registerShowIntractiveWithEdgeGesture:(BOOL)openEdgeGesture transitionDirectionAutoBlock:(void(^)(CWDrawerTransitionDirection direction))transitionDirectionAutoBlock;
- (void)cw_registerShowIntractiveWithEdgeGesture:(BOOL)openEdgeGesture
transitionDirectionAutoBlock:(void(^)(CWDrawerTransitionDirection direction))transitionDirectionAutoBlock;

/**
Custom push method 自定义的push动画
Expand All @@ -55,7 +56,8 @@
@param vc Need to push of the controller
@param duration The Drewer Hidden Animation Duration When Push. push时抽屉隐藏动画的持续时间
*/
- (void)cw_pushViewController:(UIViewController *)vc drewerHiddenDuration:(NSTimeInterval)duration;
- (void)cw_pushViewController:(UIViewController *)vc
drewerHiddenDuration:(NSTimeInterval)duration;

/**
Custom present method 自定义的present动画
Expand All @@ -70,7 +72,8 @@
@param vc Need to present of the controller
@param hidden The Drewer isHidden . present时抽屉是否隐藏
*/
- (void)cw_presentViewController:(UIViewController *)vc drewerHidden:(BOOL)hidden;
- (void)cw_presentViewController:(UIViewController *)vc
drewerHidden:(BOOL)hidden;

/**
Custom present method 自定义的dismiss动画
Expand Down
4 changes: 1 addition & 3 deletions CWLateralSlide/UIViewController+CWLateralSlide.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#import "CWDrawerTransition.h"
#import <objc/runtime.h>


@implementation UIViewController (CWLateralSlide)

// 显示默认抽屉
Expand Down Expand Up @@ -56,10 +55,9 @@ - (void)cw_registerShowIntractiveWithEdgeGesture:(BOOL)openEdgeGesture transitio
objc_setAssociatedObject(self, &CWLateralSlideAnimatorKey, animator, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

CWInteractiveTransition *interactiveShow = [CWInteractiveTransition interactiveWithTransitiontype:CWDrawerTransitiontypeShow];
[interactiveShow addPanGestureForViewController:self];
[interactiveShow setValue:@(openEdgeGesture) forKey:@"openEdgeGesture"];
[interactiveShow setValue:transitionDirectionAutoBlock forKey:@"transitionDirectionAutoBlock"];
[interactiveShow setValue:@(CWDrawerTransitionFromLeft) forKey:@"direction"];
[interactiveShow addPanGestureForViewController:self];

[animator setValue:interactiveShow forKey:@"interactiveShow"];
}
Expand Down
4 changes: 2 additions & 2 deletions CWLateralSlideDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
DEVELOPMENT_TEAM = ML49CE4G8Y;
INFOPLIST_FILE = "$(SRCROOT)/CWLateralSlideDemo/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.Chavez.CWLateralSlide11;
PRODUCT_BUNDLE_IDENTIFIER = com.Chavez.CWLateralSlide;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -427,7 +427,7 @@
DEVELOPMENT_TEAM = ML49CE4G8Y;
INFOPLIST_FILE = "$(SRCROOT)/CWLateralSlideDemo/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.Chavez.CWLateralSlide11;
PRODUCT_BUNDLE_IDENTIFIER = com.Chavez.CWLateralSlide;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (void)viewDidLoad {

// 注册手势驱动
__weak typeof(self)weakSelf = self;
[self cw_registerShowIntractiveWithEdgeGesture:NO transitionDirectionAutoBlock:^(CWDrawerTransitionDirection direction) {
[self cw_registerShowIntractiveWithEdgeGesture:YES transitionDirectionAutoBlock:^(CWDrawerTransitionDirection direction) {
if (direction == CWDrawerTransitionFromLeft) { // 左侧滑出
[weakSelf defaultAnimationFromLeft];
} else if (direction == CWDrawerTransitionFromRight) { // 右侧滑出
Expand Down
2 changes: 1 addition & 1 deletion CWLateralSlideDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.6.2</string>
<string>1.6.4</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
Expand Down

0 comments on commit 96b3b3f

Please sign in to comment.