ChavezChen / CWLateralSlide

One line of code to integrate 0 coupling side drawer!一行代码集成0耦合侧滑抽屉!
MIT License
1.28k stars 201 forks source link

好像不适用此场景”结合UIScrollView使用,滑动到最左侧滑出左侧抽屉,滑动到最右侧滑出右侧抽屉“ #5

Closed idozhuoyong closed 6 years ago

idozhuoyong commented 6 years ago

目前好像不适用此场景”结合UIScrollView使用,滑动到最左侧滑出左侧抽屉,滑动到最右侧滑出右侧抽屉“,也不知道是不是没用对方法😔

在巨人的肩膀上😜,简单修改了下,ps:新人一枚,若改出问题,请原谅😜 1、在WynterW大神基础上修改了UIScrollView方法 `/**

2、参照原有注册手势驱动方法之外添加下面的方法 `/** 注册手势驱动方法,侧滑呼出的方向自动确定,一般在viewDidLoad调用,调用之后会添加一个支持侧滑的手势到本控制器

@param openEdgeGesture 是否开启边缘手势,边缘手势的开始范围为距离边缘50以内 @param transitionDirectionAutoBlock 手势过程中执行的操作。传整个点击present的事件即可(看demo的使用) */

3、修改CWInteractiveTransition.m文件 新增属性 @property (nonatomic, copy) void(^transitionDirectionAutoBlock)(CWDrawerTransitionDirection direction); /* 默认NO */ @property (nonatomic, assign) BOOL isAutoDirection;

修改方法 `- (void)showBeganTranslationX:(CGFloat)x gesture:(UIPanGestureRecognizer *)pan { //NSLog(@"---->%f", x); if (self.isAutoDirection == YES) { if (x >= 0) { _direction = CWDrawerTransitionDirectionLeft; } else { _direction = CWDrawerTransitionDirectionRight; } }

if ((x < 0 && _direction == CWDrawerTransitionDirectionLeft) || (x > 0 && _direction == CWDrawerTransitionDirectionRight)) return;

CGFloat locX = [pan locationInView:_weakVC.view].x;
//    NSLog(@"locX: %f",locX);
if (_openEdgeGesture && ((locX > 50 && _direction == CWDrawerTransitionDirectionLeft) || (locX < CGRectGetWidth(_weakVC.view.frame) - 50 && _direction == CWDrawerTransitionDirectionRight))) {
    return;
}
self.interacting = YES;
if (_transitionBlock) {
    _transitionBlock();
}

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

}`

4、调用 `- (void)viewDidLoad { [super viewDidLoad];

self.tabBarController.view.backgroundColor = [UIColor whiteColor];

if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
    self.edgesForExtendedLayout = UIRectEdgeNone;
}

[self setupNavBarItem];

[self setupScrollView];

// 注册手势驱动
__weak typeof(self)weakSelf = self;
[self cw_registerShowIntractiveWithEdgeGesture:NO transitionDirectionAutoBlock:^(CWDrawerTransitionDirection direction) {
    //NSLog(@"direction = %ld", direction);
    if (direction == CWDrawerTransitionDirectionLeft) {
        [weakSelf leftClick];
    } else if (direction == CWDrawerTransitionDirectionRight) {
        [weakSelf rightClick];
    }
}];

// [self cw_registerShowIntractiveWithEdgeGesture:NO direction:CWDrawerTransitionDirectionLeft transitionBlock:^{ // [weakSelf leftClick]; // }];

// [self cw_registerShowIntractiveWithEdgeGesture:NO direction:CWDrawerTransitionDirectionRight transitionBlock:^{ // [weakSelf rightClick]; // }];

}`

ChavezChen commented 6 years ago

你好,目前手势只支持增加一个。。。😢

ChavezChen commented 6 years ago

你那样加,我之前尝试过。。应该是不行的,原因好像是因为 每次动画对象CWDrawerTransition都会变,每次都是不同的。没法匹配到手势和动画。具体我忘记了。。暂时没法实现哦

ChavezChen commented 6 years ago

你先一边用手势,一边不用吧。。。。我再想想办法,,因为这种情况挺少见再加上之前整了一会没什么好办法我就放那了。

idozhuoyong commented 6 years ago

好的,谢谢,不过我按照上面我说的修改之后两边都能用手势,目前好像没毛病,非常感谢

idozhuoyong commented 6 years ago

CWLateralSlide-master.zip 这是在您的案例上修改后的工程,谢谢

ChavezChen commented 6 years ago

我看了一下你改的,给你10086个赞😄,那我只能恬不知耻的把你改的提交上去了😁哈哈,老哥没意见吧~

ChavezChen commented 6 years ago

测试了一下,没什么大的问题,有一个小问题在边缘手势开启的情况下,右侧滑出被拦截了,我这边把之前的判断修改调整过后会将代码更新上去,非常感谢你的贡献🙏之前会错你的意思了,不好意思。。

idozhuoyong commented 6 years ago

嗯嗯,好,有时候是我没表达清楚,不好意思哈,谢谢,嘿嘿