简体   繁体   English

如何在像目标这样的圆内绘制多个圆并获得特定圆的触摸事件?

[英]How to draw multiple circles within circle like target and get touch event of particular circle?

I want to draw target view like this- 我想这样绘制目标视图 在此处输入图片说明

And get touch event of a particular circle. 并获取特定圈子的触摸事件。 eg If user touch between circle 7 then fill black color of circles up to circles 7. 例如,如果用户在第7圈之间触摸,则将圆形的黑色填充到第7圈。

Currently I have two ways to implement this functionality: 1) Take 10 UIImageView and put on each other and touch of an image view change the colors of image view's according to conditions. 目前,我有两种方法可以实现此功能:1)取10个UIImageView并互相戴上,然后触摸图像视图即可根据情况更改图像视图的颜色。

2) Take UIView and draw 20 color gradient (10 for black border line and 10 for white spaces) and save frame of each gradient. 2)使用UIView并绘制20个颜色渐变(黑色边框线为10,空白线条为10),并保存每个渐变的帧。 After that get user's touch area then change color according to that. 之后,获取用户的触摸区域,然后根据该颜色进行更改。

I am looking for a better solution. 我正在寻找更好的解决方案。

why not have a single image, and calculate the radius based on the touch point - all you need to know is the centre position. 为什么没有一张图片,然后根据触摸点计算半径-您只需要知道中心位置即可。

Instead of radius, what you really need is an index from 0 to 11 for your bands - if they are equal thickness, you can do that in a single calculation - take the integer part of (11 * radius / radiusFull) 您真正需要的是波段的索引,而不是半径,范围是0到11-如果它们的厚度相等,则可以在一次计算中完成-取(11 * radius / radiusFull)的整数部分

If the bulls-eye is a different size, you may need to add some more code. 如果靶心大小不同,则可能需要添加更多代码。

Either way, you should be able to do it all with a single image - generated on the fly, or simply loaded - and a bit of simple maths. 无论哪种方式,您都应该能够使用单个图像(即时生成或简单地加载)以及一些简单的数学来完成所有操作。

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

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