我的手勢識別器有問題。我的目標是實現在我的表格視圖中使用滑動刪除。但我認爲其他手勢彼此衝突。我正在使用這個庫romaonthego/REFrostedViewController 這是我的漢堡菜單的一個庫,這個庫有一個pangesture功能。我認爲衝突是在手勢中。因爲當我在另一個項目中運行我的tableview代碼時,它正在工作。請幫助,謝謝您。手勢衝突UITableView滑動刪除iOS
回答
首先...看看,如果你有這個
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
和第二...
嘗試添加該
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if ([gestureRecognizer.view isKindOfClass:[UITableView class]]) {
return YES;
} else {
return NO;
}
}
那麼...你有什麼消息嗎? – TonyMkenu 2014-09-04 10:00:27
對不起,我已經通過參考漢堡菜單的手勢來解決我的問題。謝謝你的回答:) – 2014-10-09 01:44:59
@AlvinJohnTandoc我在當前的項目中遇到類似的問題。我假設TonyMkenu提供的解決方案爲您工作。如果我的假設是正確的,你能否告訴我該把代碼放在哪裏(功能在答案中提供)?現在我的代碼不會在任何地方使用這些函數。那麼我應該把它放在菜單類還是我自己的視圖控制器類中? – 2015-05-29 12:47:44
我有一個類似的問題,我最終做的和TonyMkenu類似,但是有更多的認識者認爲y OU需要允許:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (otherGestureRecognizer.delegate == self)
return NO;
//if otherGestureRecognizer is swipe to delete from a UITableView cancel slide menu recognizers
if ([[otherGestureRecognizer.view class] isSubclassOfClass:[UITableView class]])
{
NSLog(@"Allow1 %@", [otherGestureRecognizer description]);
return YES;
}
if([[otherGestureRecognizer.view class] isSubclassOfClass:[UITableViewCell class]] ||
[NSStringFromClass([otherGestureRecognizer.view class]) isEqualToString:@"UITableViewCellScrollView"] ||
[NSStringFromClass([otherGestureRecognizer.view class]) isEqualToString:@"UITableViewWrapperView"])
{
NSLog(@"Allow&Disable %@", [otherGestureRecognizer description]);
if(gestureRecognizer.delegate == self)
{//cancel the slide menu recognizer
gestureRecognizer.enabled = NO;
gestureRecognizer.enabled = YES;
}
return YES;
}
NSLog(@"Deny %@", [otherGestureRecognizer description]);
return NO;
}
編輯:更新了iOS的11
其他的答案是有幫助的,但對我來說最好的解決辦法是應該做的邏輯shouldRequireFailureOfOtherGesture
像所以:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (gestureRecognizer == self.pan) {
return YES;
}
return NO;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (gestureRecognizer == self.pan) {
// iOS 10
if ([NSStringFromClass([otherGestureRecognizer.view class]) isEqualToString:@"UITableViewWrapperView"]) {
return YES;
}
// iOS 11
else if ([otherGestureRecognizer isMemberOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer.view isKindOfClass:[UITableView class]]) {
return YES;
}
}
return NO;
}
這在我的情況下有更好的行爲。我還在我的平底鍋手勢上使用了delaysTouchesBegan = YES
。可能有用!
在iOS 11中,希望這可以幫助你。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if ([[otherGestureRecognizer.view class] isSubclassOfClass:[UITableView class]]) {
if ([otherGestureRecognizer isKindOfClass: [UIPanGestureRecognizer class]]) {
UIPanGestureRecognizer *otherPan = (UIPanGestureRecognizer *)otherGestureRecognizer;
CGPoint translation = [otherPan translationInView:otherGestureRecognizer.view];
return translation.x < 0;
}
}
return NO;
}
- 1. UITableView的滑動手勢衝突刷卡
- 2. iOS - UITableView Pan手勢
- 3. 平移手勢 - 輕掃手勢衝突
- 4. 覆蓋UITableView上的滑動手勢
- 5. UIView滑動手勢與目標c中的tableview衝突
- 6. UIControl手勢與UIPageViewController衝突
- 7. 2 UIPageViewControllers手勢衝突
- 8. 滑動手勢滑動UIViews
- 9. ios - UITableView刪除按鈕不會對手勢做出反應
- 10. 與對象IOS滑動手勢
- 11. 在Flash CS6中iOS的滑動手勢
- 12. 的UITableView:滾動和滑動手勢是錄音/更新並在IOS可能刪除行後禁用10
- 13. UITextView滑動手勢
- 14. iOS滑動UITableView
- 15. 如何在UITableView的滑動刪除手勢中提供自定義刪除按鈕?
- 16. 從手勢文件中刪除手勢
- 17. iphone - 單擊手勢與雙人手勢衝突
- 18. 如何檢測自定義UITableviewCell中的滑動刪除手勢?
- 19. TableView手勢識別器影響滑動刪除行
- 20. 添加滑動手勢,無法滑動
- 21. UIWebView覆蓋滑動手勢
- 22. 用手勢滑動視圖
- 23. 滑動手勢給NSException
- 24. UIButton和滑動手勢
- 25. 滑動手勢識別UIWebView
- 26. UITextfield干擾滑動手勢
- 27. 用雙指滑動手勢
- 28. ListView中滑動手勢 - Android
- 29. Android sqlite刪除衝突衝突
- 30. UItableview滑動刪除iOS 11不刷新/重新加載數據
我認爲...你必須禁用「panGestureEnabled」並手動呈現「菜單」[self.frostedViewController presentMenuViewController]; – TonyMkenu 2014-08-27 11:49:55
但我也需要平移手勢。我禁用了平移手勢,但它根本不工作。我看到一些應用程序在那裏使用平移手勢菜單和手勢來刪除表中的數據。我想知道他們是如何管理兩輪2平移手勢。 T_T – 2014-08-27 11:53:39
但是..你有什麼衝突?您無法呈現菜單......或者您無法滑動單元格? – TonyMkenu 2014-08-27 12:54:57