2015-10-01 26 views
0

在我UICollectionViewCell S的頂部在我UICollectionView我已經覆蓋在UIButton攔截接觸,所以我可以作出反應,以便更精確的觸摸事件。問題是,現在收集視圖不再獲得didSelectItemAtIndexPath消息。 (出於顯而易見的原因...按鈕吸收了聯繫,沒有信令採集認爲該項目被選中。)UICollectionViewCell信號UICollectionView didSelect

有沒有一種方式,電池選擇信號的採集看法?我見過類似的問題,但似乎沒有一個令人信服的答案。

回答

1

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

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 
    } 
} 
+0

我真的很喜歡這個解決方案不僅因爲它解決了我的問題,但我學會了如何傳播觸摸。謝謝! –

相關問題