UITapGestureRecognizer working on UIImageView but not on UILabel

后端 未结 2 1006
渐次进展
渐次进展 2021-01-24 07:25

I have a UITableViewCell class named CommentsTableViewCell which among other things includes a UIImageView and a UILabel.

2条回答
  •  不知归路
    2021-01-24 07:45

    You need to create two UITapGestureRecognizer object because UITapGestureRecognizer works with single UI element object. So create second TapGestureRecognizer and assign one to UILabel and one to UIImageView.

    From UIGestureRecognizer documentation.

    A gesture recognizer operates on touches hit-tested to a specific view and all of that view’s subviews. It thus must be associated with that view. To make that association you must call the UIView method addGestureRecognizer(_:). A gesture recognizer doesn’t participate in the view’s responder chain.

提交回复
热议问题