最近有一個需求网严,在JXPagerView的子控制器里的一個UITableView需要左滑刪除功能相速,正常來說左滑刪除功能只要在列表的代理方法里實(shí)現(xiàn):
/**
設(shè)置左滑按鈕
*/
-(NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleNormal) title:@"置頂" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
}];
return @[action1];
}
這樣就可以設(shè)置好左滑的按鈕
但是
當(dāng)這個方法會跟JXPagerView的左右滾動會有沖突仇参,導(dǎo)致左滑會不靈敏
這個問題其實(shí)JXPagerView有給出解決方案:
JXPagerViewDelegate
提供了一個可選的協(xié)議方法:
/**
返回自定義UIScrollView或UICollectionView的Class
某些特殊情況需要自己處理列表容器內(nèi)UIScrollView內(nèi)部邏輯奄侠。比如項(xiàng)目用了FDFullscreenPopGesture钝吮,需要處理手勢相關(guān)代理藻治。
@param pagerView JXPagerView
@return 自定義UIScrollView實(shí)例
*/
- (Class)scrollViewClassInlistContainerViewInPagerView:(JXPagerView *)pagerView;
在JXCategoryView中這個方法是:
@optional
/**
返回自定義UIScrollView或UICollectionView的Class
某些特殊情況需要自己處理UIScrollView內(nèi)部邏輯碘勉。比如項(xiàng)目用了FDFullscreenPopGesture,需要處理手勢相關(guān)代理桩卵。
@param listContainerView JXCategoryListContainerView
@return 自定義UIScrollView實(shí)例
*/
- (Class)scrollViewClassInlistContainerView:(JXCategoryListContainerView *)listContainerView;
看到這個我就知道怎么弄了验靡,咱們可以自定義一個自定義UIScrollView或UICollectionView 在里面實(shí)現(xiàn)手勢的控制,我這里初始化[[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self]
因此需要自定義一個UIScorllView來控制手勢雏节,讓它兼容多種手勢共存
1.ServiceScrollView.h
@interface ServiceScrollView : UIScrollView<UIGestureRecognizerDelegate>
@end
2.ServiceScrollView.m
@implementation ServiceScrollView
/**
重載UIScrollView手勢
是否支持多手勢觸發(fā)胜嗓,1.返回YES,則可以多個手勢一起觸發(fā)方法钩乍;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的控制器中實(shí)現(xiàn)JXCategoryListContainerViewDelegate
- (Class)scrollViewClassInlistContainerView:(JXCategoryListContainerView *)listContainerView
{
return [ServiceScrollView class];
}
然后還有一個注意的地方是辞州,JXPagerListRefreshView構(gòu)建的時候listContainerType要選ScrollView
[[JXPagerListRefreshView alloc] initWithDelegate:self listContainerType:(JXPagerListContainerType_ScrollView)];
不然的話,不會走ServiceScrollView.m里面的方法,如果設(shè)置的是JXPagerListContainerType_CollectionView
的話,ServiceScrollView
繼承的應(yīng)該是UICollectionView
這樣寥粹,就可以了