简体   繁体   English

简单的可伸缩非矩形形状

[英]Simple Tappable Non-Rectangular Shape

I have to create a very simple GUI for an iPad application. 我必须为iPad应用程序创建一个非常简单的GUI。

I have a 1024x768 png and I want to use this file for the GUI. 我有一个1024x768 png,我想将这个文件用于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. 你可以通过覆盖来实现代码- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event在视图中显示图片。 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. 制作一个UIImageView,显示一个显示梯形的图像,否则是透明的。

Turn on the UIImageView's userInteractionEnabled to make it tappable. 打开UIImageView的userInteractionEnabled以使其可以播放。

Put a UITapGestureRecognizer on the UIImageView to respond to the tap. 在UIImageView上放置UITapGestureRecognizer以响应点击。

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 . 要了解用户触摸的点是否透明,请参阅检索UIImage的像素alpha值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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