iOS JXPagerView或JXCategoryView和U
2021-08-12 本文已影响0人
夜空丶
最近有一个需求,在JXPagerView的子控制器里的一个UITableView需要左滑删除功能,正常来说左滑删除功能只要在列表的代理方法里实现:
/**
设置左滑按钮
*/
-(NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleNormal) title:@"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
}];
return @[action1];
}
这样就可以设置好左滑的按钮
但是
当这个方法会跟JXPagerView的左右滚动会有冲突,导致左滑会不灵敏
这个问题其实JXPagerView有给出解决方案:
JXPagerViewDelegate
提供了一个可选的协议方法:
/**
返回自定义UIScrollView或UICollectionView的Class
某些特殊情况需要自己处理列表容器内UIScrollView内部逻辑。比如项目用了FDFullscreenPopGesture,需要处理手势相关代理。
@param pagerView JXPagerView
@return 自定义UIScrollView实例
*/
- (Class)scrollViewClassInlistContainerViewInPagerView:(JXPagerView *)pagerView;
在JXCategoryView中这个方法是:
@optional
/**
返回自定义UIScrollView或UICollectionView的Class
某些特殊情况需要自己处理UIScrollView内部逻辑。比如项目用了FDFullscreenPopGesture,需要处理手势相关代理。
@param listContainerView JXCategoryListContainerView
@return 自定义UIScrollView实例
*/
- (Class)scrollViewClassInlistContainerView:(JXCategoryListContainerView *)listContainerView;
看到这个我就知道怎么弄了,咱们可以自定义一个自定义UIScrollView或UICollectionView 在里面实现手势的控制,我这里初始化[[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self]
因此需要自定义一个UIScorllView来控制手势,让它兼容多种手势共存
1.ServiceScrollView.h
@interface ServiceScrollView : UIScrollView<UIGestureRecognizerDelegate>
@end
2.ServiceScrollView.m
@implementation ServiceScrollView
/**
重载UIScrollView手势
是否支持多手势触发,1.返回YES,则可以多个手势一起触发方法;2.返回NO则为互斥
// called when the recognition of one of gestureRecognizer or otherGestureRecognizer would be blocked by the other
// return YES to allow both to recognize simultaneously. the default implementation returns NO (by default no two gestures can be recognized simultaneously)
//
// note: returning YES is guaranteed to allow simultaneous recognition. returning NO is not guaranteed to prevent simultaneous recognition, as the other gesture's delegate may return YES
*/
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (gestureRecognizer.state != UIGestureRecognizerStatePossible) {
return YES;
} else {
return NO;
}
}
在使用JXCategoryView的控制器中实现JXCategoryListContainerViewDelegate
- (Class)scrollViewClassInlistContainerView:(JXCategoryListContainerView *)listContainerView
{
return [ServiceScrollView class];
}
然后还有一个注意的地方是,JXPagerListRefreshView构建的时候listContainerType要选ScrollView
[[JXPagerListRefreshView alloc] initWithDelegate:self listContainerType:(JXPagerListContainerType_ScrollView)];
不然的话,不会走ServiceScrollView.m里面的方法,如果设置的是JXPagerListContainerType_CollectionView
的话,ServiceScrollView
继承的应该是UICollectionView
这样,就可以了