简体   繁体   中英

Simple Tappable Non-Rectangular Shape

I have to create a very simple GUI for an iPad application.

I have a 1024x768 png and I want to use this file for the GUI. I have to make an area of this png tappable and able to run some action. This area is not a rectangle (it's a trapezoid) so I can't create a button. Is it possible somehow?

you can do it in code by overriding - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event and - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event in the view that's displaying the image. that'll mean you have to decide whether a point is within the touch area of the image.

Make a UIImageView that displays an image which shows the trapezoid and is otherwise transparent.

Turn on the UIImageView's userInteractionEnabled to make it tappable.

Put a UITapGestureRecognizer on the UIImageView to respond to the tap.

In the tap gesture recognizer's action handler, respond only if the point where the user tapped is non-transparent. To learn whether the point the user touched is transparent, see Retrieving a pixel alpha value for a UIImage .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM