将图像分成区域

发布于 2024-11-17 03:58:35 字数 205 浏览 2 评论 0原文

我有一个视图,其下面有一个图像视图和一个表格视图。图像视图包含人体图像。现在我想做的是将图像分成三个部分:头部、胸部和腹腔。表格视图也有三行,每一行对应于上面提到的正文部分。当我选择或单击这些区域中的任何一个时,我想滚动表格的相应行并导航到另一个视图控制器,该视图控制器将用作详细视图控制器。假设我选择 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愛上了 2024-11-24 03:58:35

您可以使用附加到图像视图的 UITapGestureRecognizer 实例轻松完成此操作。首先,您必须将 UIImageViewuserInteractionEnabled 设置为 YES。连接手势识别器后,您应该将触摸解析到手势处理程序中的区域。

- (void)tap:(UITapGestureRecognizer *)tapGesture {
    CGPoint locationInView = [tapGesture locationInView:tapGesture.view];

    /* Resolve the location here */
}

现在分辨率取决于您定义区域的方式。如果它们只是矩形,则声明三个 CGRect 对象作为实例变量,并适当地设置它们并执行类似的操作,

if ( CGRectContainsPoint(headRect, locationInView) ) {
    /* It's a head, load its view controller */
} else if ( ... ) {
    ....

或者如果区域更复杂一点,请使用 UIBezierPath 或CGPathRef。

You can easily do this using a UITapGestureRecognizer instance attached to the image view. First off, you will have to set the UIImageView's userInteractionEnabled to YES. After attaching the gesture recognizer, you should resolve the touch to its region in the gesture handler.

- (void)tap:(UITapGestureRecognizer *)tapGesture {
    CGPoint locationInView = [tapGesture locationInView:tapGesture.view];

    /* Resolve the location here */
}

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,

if ( CGRectContainsPoint(headRect, locationInView) ) {
    /* It's a head, load its view controller */
} else if ( ... ) {
    ....

Or if the regions are a bit more complicated, use UIBezierPath or CGPathRef.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文