MMDrawerController 是一個很好用的實現(xiàn)抽屜效果的第三方類辖试,但有時候當(dāng)我們在中心視圖的子視圖控制器中需要使用手勢進行其他操作的時候會產(chǎn)生手勢沖突辜王,導(dǎo)致運行效果不符合我們的想象。那么問題來了罐孝,該怎么解決沖突問題呢呐馆?
下面是我在使用過程中的個人總結(jié):
需求:
1、只有左抽屜和中心視圖控制器肾档,在中心視圖的子視圖控制器右滑可以打開左抽屜摹恰。
2辫继、中心視圖的子視圖控制器中的 Cell 可通過滑動手勢顯示自定義 Cell 中的刪除按鈕
問題:
1怒见、由于刪除 Cell 的左滑手勢和 MMDrawerController 的打開右抽屜的左滑手勢有沖突,導(dǎo)致左滑顯示自定義 Cell 刪除按鈕的方法不響應(yīng)姑宽。
期待效果:
1遣耍、解除刪除 Cell 的手勢沖突
2、右滑可以打開左抽屜
思考過程:
MMDrawerController 中應(yīng)該有一個識別手勢的方法炮车,只要找到這個方法問題就可以得到解決舵变。
解決過程:
1酣溃、在 MMDrawerController 文件夾下的各個.m
文件中通過 Command+F 搜尋 GestureRecognizer,最終在 MMDrawerController 這個類中找到這個方法
-(MMOpenDrawerGestureMode)possibleOpenGestureModesForGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer withTouch:(UITouch*)touch纪隙;
2赊豌、在這個方法中找到了 PointContainedWithinCenterViewContentRect:
這個判斷條件,按住 Command 點擊后跳到它所在的位置绵咱,在這里找到了問題所在碘饼。解決方式如下:
MMDrawerController.m 1443 行
-(BOOL)isPointContainedWithinCenterViewContentRect:(CGPoint)point{
// CGRect centerViewContentRect = self.centerContainerView.frame;
// 原文意思是把觸發(fā)抽屜的手勢識別放在整個屏幕中
CGRect centerViewContentRect = CGRectMake(0, 0, 50, self.centerContainerView.frame.size.height);
// 修改后的意思是把觸發(fā)打開抽屜手勢識別放在屏幕左側(cè)寬50,高為屏幕高度的 rect 中
centerViewContentRect = CGRectIntersection(centerViewContentRect,self.childControllerContainerView.bounds);
return (CGRectContainsPoint(centerViewContentRect, point) && [self isPointContainedWithinNavigationRect:point] == NO);
}