Note that there are some explanatory texts on larger screens.

plurals
  1. PODetect touches only on non-transparent pixels of UIImageView, efficiently
    primarykey
    data
    text
    <p>How would you detect touches only on non-transparent pixels of a <code>UIImageView</code>, efficiently?</p> <p>Consider an image like the one below, displayed with <code>UIImageView</code>. The goal is be to make the gesture recognisers respond only when the touch happens in the non-transparent (black in this case) area of the image.</p> <p><img src="https://i.stack.imgur.com/OHCHD.png" alt="enter image description here"></p> <h2>Ideas</h2> <ul> <li>Override <a href="http://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/hitTest:withEvent:" rel="noreferrer"><code>hitTest:withEvent:</code></a> or <a href="http://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/pointInside:withEvent:" rel="noreferrer"><code>pointInside:withEvent:</code></a>, although this approach might be terribly inefficient as these methods get called many times during a touch event.</li> <li>Checking if a single pixel is transparent might create unexpected results, as fingers are bigger than one pixel. Checking a circular area of pixels around the hit point, or trying to find a transparent path towards an edge might work better. </li> </ul> <h2>Bonus</h2> <ul> <li>It'd be nice to differentiate between outer and inner transparent pixels of an image. In the example, the transparent pixels inside the zero should also be considered valid.</li> <li>What happens if the image has a transform?</li> <li>Can the image processing be hardware accelerated?</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload