Swift 3- How to get button in UICollectionViewCell work

前端 未结 6 766
夕颜
夕颜 2020-12-09 23:19

I am trying to implement an Edit button inside a cell.

Please refer to image:

What I done so far:

MainController:

class MainCo         


        
6条回答
  •  半阙折子戏
    2020-12-09 23:51

    If touch action on UIButton is not detecting.

    To enable touch action on the UIButton of your Custom UICollectionCell, add the below method in your Custom UICollectionCell class.

    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        var view = myButton.hitTest(myButton.convert(point, from: self), with: event)
        if view == nil {
            view = super.hitTest(point, with: event)
        }
    
        return view
    }
    

提交回复
热议问题