iOS JXPagerView或JXCategoryView和UITableViewCell左滑刪除沖突問題

最近有一個需求,在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

這樣,就可以了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容