重点说明: 侧滑手势处理的结果是:当前页面处于第一页的时候,才允许侧滑手势返回上一页。处于其他页面的时候,在屏幕边缘侧滑只会响应列表页面的左右滚动。这样做的目标便于用户停留在当前页面,进行列表的切换浏览。
如果产品经理不需要这样的特性,希望侧滑手势任何情况都能响应,就不需要参看此教程,不做任何处理即可。
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//处于第一个item的时候,才允许屏幕边缘手势返回
self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
//离开页面的时候,需要恢复屏幕边缘手势,不能影响其他页面
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
(void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}
- 设置代理:
self.navigationController.interactivePopGestureRecognizer.delegate = self;
- 设置手势代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}