将图像分成区域
我有一个视图,其下面有一个图像视图和一个表格视图。图像视图包含人体图像。现在我想做的是将图像分成三个部分:头部、胸部和腹腔。表格视图也有三行,每一行对应于上面提到的正文部分。当我选择或单击这些区域中的任何一个时,我想滚动表格的相应行并导航到另一个视图控制器,该视图控制器将用作详细视图控制器。假设我选择 head,我想导航到另一个详细解释 head 的页面。当我选择任何行时,我会得到相同的效果。
I have a view with an imageview and a tableview below it. The imageview contains an image of a human body. Now what I'd like to do is to separate the image into three portions: The head, the thorax and the abdominal cavity. The tableview also has three rows, each corresponding to the sections of the body mentioned above.When I select or click any of these regions I want to scroll through the corresponding rows of the table and navigate to another viewcontroller which will serve as a detail view controller. So let's say I choose head, I want to navigate to another page that explains head in detail. I get the same effect when I select any of the rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用附加到图像视图的
UITapGestureRecognizer
实例轻松完成此操作。首先,您必须将UIImageView
的userInteractionEnabled
设置为YES
。连接手势识别器后,您应该将触摸解析到手势处理程序中的区域。现在分辨率取决于您定义区域的方式。如果它们只是矩形,则声明三个 CGRect 对象作为实例变量,并适当地设置它们并执行类似的操作,
或者如果区域更复杂一点,请使用 UIBezierPath 或CGPathRef。
You can easily do this using a
UITapGestureRecognizer
instance attached to the image view. First off, you will have to set theUIImageView
'suserInteractionEnabled
toYES
. After attaching the gesture recognizer, you should resolve the touch to its region in the gesture handler.Now resolution is based on how you will define the regions. If they are just rectangles, declare three
CGRect
objects as instance variables and set them appropriately and do something like this,Or if the regions are a bit more complicated, use
UIBezierPath
orCGPathRef
.