UIView 绝对屏幕点 [英] UIView absolute screen point

查看:55
本文介绍了UIView 绝对屏幕点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以获取 UIView 的绝对点?绝对是指 UIView 相对于 iPad 上 1024x768 的位置?

Is there an easy way of getting the absolute point of UIView? By absolute I mean the location of the UIView relative to 1024x768 on an iPad?

我需要一个简单的方法,因为我在视图控制器呈现的视图中的 UITableViewCell 内有一个 UIButton,该视图控制器是另一个视图控制器的子级,重复到第五个或第六个视图控制器.由于这种复杂的设计,我需要 UIButton 的绝对矩形,以便我可以在主"视图控制器上显示 UIActionSheet.

I need an easy way because I have a UIButton inside a UITableViewCell inside a UITableView inside a view presented by a viewcontroller that is a child of another view controller repeating to the fifth or sixth view controller. And due to this complex design I need the absolute rect of the UIButton so I can display an UIActionSheet on the "main" viewcontroller.

推荐答案

所以我最终使用 UITapGestureRecognizer 代替并像这样计算位置:

So I ended up using UITapGestureRecognizer instead and calculating the position like this:

    CGPoint gestureViewLocation = [gesture locationInView:gesture.view];
    CGPoint absoluteLocation = [gesture locationInView:self.parentViewController.view];
    CGRect fromRect = CGRectMake(absoluteLocation.x-gestureViewLocation.x, //subtract to we get point relative to gesture view
                                 absoluteLocation.y-gestureViewLocation.y, //subtract to we get point relative to gesture view
                                 gesture.view.frame.size.width,
                                 gesture.view.frame.size.height);

这篇关于UIView 绝对屏幕点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆