Tap detection not working on UIImageView

前端 未结 1 1396
终归单人心
终归单人心 2020-12-12 05:38

In my .m file I added:

@property (strong, nonatomic) UIImageView *star1;

Then in a method I did:

UIImage *star1Image;
star1         


        
相关标签:
1条回答
  • 2020-12-12 06:19

    So, since components like UILabel or UIImageView aren't design to be "touchable", to add a "touchable" feature (like a UITapRecognizer), you have to set their userInteractionEnabled to YES.

    So, even if you set this property correctly for your UIImageView (star1), since you add it as a subview of ratingLabelBody, you couldn't trigger your UITapGestureRecognizer (imgTouchUp:).
    You have to do the same to the parent view of your star1, which is ratingLabelBody.

    Translated with code, you just had to do:

    [ratingLabelBody setUserInteractionEnabled:YES];
    
    0 讨论(0)
提交回复
热议问题