簡體   English   中英

UICollectionViewCell信號到UICollectionView didSelect

[英]UICollectionViewCell signal to UICollectionView didSelect

在我的UICollectionViewCellUICollectionView我覆蓋了一個UIButton來攔截觸摸,因此我可以更精細地響應觸摸事件。 問題在於,現在集合視圖不再獲取didSelectItemAtIndexPath消息。 (出於明顯的原因,該按鈕吸引了觸摸,並未向收藏夾視圖表明已選中該項目。)

有沒有一種方法可以向收集視圖發送信號,表明已選中該單元格? 我見過類似的問題,但似乎沒有一個令人信服的答案。

您可以重寫UIView [和子類]上的pointInside:withEvent:消息,並返回false以繼續傳播touch事件。

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/pointInside:withEvent

class PassThroughButton: UIButton {
  override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
    // do something
    // then continue event propigation
    return false
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM