Detect touches only on non-transparent pixels of UIImageView, efficiently

前端 未结 3 695
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 00:34

How would you detect touches only on non-transparent pixels of a UIImageView, efficiently?

Consider an image like the one below, displayed with UI

3条回答
  •  广开言路
    2020-12-01 01:04

    On github, you can find a project by Ole Begemann which extends UIButton so that it only detects touches where the button's image is not transparent.

    Since UIButton is a subclass of UIView, adapting it to UIImageView should be straightforward.

    Hope this helps.

提交回复
热议问题