2016-07-13 31 views
0

我已將UILongPressGestureRecognizer添加到我的UICollectionView,它位於UIScrollView的子類中。 (UIScrollView被分頁,所以有3個水平堆疊UIViewController s)。UIScrollView中的UICollectionView:長按

我的代碼添加UILongPressGestureRecognizer

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; 
longPress.delegate = self; 
longPress.minimumPressDuration = 0.5; 
longPress.delaysTouchesBegan = YES; 
[self.collectionView addGestureRecognizer:longPress]; 

而一個NSLoghandleLongPress:方法。目前我堅持UICollectionViewCell,它突出顯示,但長按沒有激活。我相信我的UIScrollView子類正在消耗長時間按壓,而不是傳遞到UICollectionView。當我擡起手指時,將調用didSelectItemAtIndexPath:方法。

在我UIScrollView子類中,我唯一的自定義如下:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer { 
// This line enables the swipe to delete in the Messaging VC. 
return ([otherGestureRecognizer.view.superview isKindOfClass:[UITableView class]]); 
} 

這樣做是爲了使細胞重擊在我UITableView,這是我UIScrollView的頁面之一。刷卡工作沒有問題,我也嘗試了一些類似的檢查UICollectionViewUICollectionViewCell在這裏,但還沒有得到長按註冊呢。任何意見讚賞。

編輯:我在另一個UICollectionView上加了長按,它功能正常,但單元格從不顯示突出顯示/選定狀態。我想這是一個線索,爲什麼我不能得到這個長按新手勢。

回答

0

我的問題是我在-init方法中添加了手勢識別器。這沒有用。只需將代碼移至-viewDidLoad即可解決問題。

相關問題