I managed to mask views using similar approach as here : How to mask UIViews in iOS
But now I need to detect touches in this masked view. Gesture recognisers and buttons would detect touched in bounds area, basically ignoring the mask. So I think if I could get CGPath from my mask image, it would be easy to handle touches. Any suggestions about how to get CGPath from mask image?
I managed to mask views using similar approach as here : How to mask
Share
You could set the
UIGestureRecognizer‘s delegate and override- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch1 . Get the location of the touch in the recognizer’s view
- (CGPoint)locationInView:(UIView *)view2 . Find out the alpha channel of the image at that location. For that, use this code (for efficiency, you can recalculate the transparent values ahead of time, for the whole image, and store them into a buffer so you don’t have to copy the alpha buffer every time. I kept it simple here and did it for a single pixel. If you want to see how to do the whole image at once, look at this post.