Incorporating Gesture Support
重點:你應(yīng)該對collection view加手勢遇西,而不是一個具體的cell或view.
collectionview 對單點手勢已經(jīng)有delegate去監(jiān)聽了馅精。所以,你只能加雙擊手勢或其它非單擊手勢粱檀。
下面的代碼洲敢,展示了怎么讓collection view 響應(yīng)您的雙擊手勢而不是響應(yīng)delegate里的選擇/高亮手勢。
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.delaysTouchesBegan = YES;
tapGesture.numberOfTapsRequired = 2;
[self.collectionView addGestureRecognizer:tapGesture];
你可以通過設(shè)置delaysTouchesBegan或cancelsTouchesInView屬性 true,來讓您的手勢的優(yōu)先級別高于默認(rèn)選擇監(jiān)聽者茄蚯。當(dāng)手勢注冊了压彭,你首先會查看你的手勢是否有優(yōu)先級。只有當(dāng)輸入對你的手勢無效時渗常,那里delegate的方法才會像平時一樣會調(diào)用壮不。