如何获取 UINavigationController 中使用的 UIView 原点的 x/y 坐标?

发布于 2024-12-05 04:44:45 字数 926 浏览 0 评论 0原文

如何获取 UINavigationController 中使用的 UIView 原点的 x/y 坐标?

也就是说,我有一个 UINavigationController iPhone 应用程序设置。我将一个新视图(称为 CustomUIView)推送到堆栈上。如何确定 CustomView 视图相对于整个 iPhone 屏幕的绝对原点(x/y 坐标)?也就是说,所以它不应该是 0,0,因为它应该考虑顶部的导航栏等。

我注意到我得到: * 对于 NavController:frame = (0 0; 320 480) * 对于customViewController.view:frame = (0 0; 320 416) * 对于customView本身:frame = (0 0; 320 396)

所以问题是,当我在customView代码本身中,并且我得到它的框架时,它给了我0,0作为原点...

背景:I正在尝试将图像定位在customView上某个位置的中心,但它似乎是偏移的,我猜测是因为当我尝试设置它相对于customView的位置时,也许我应该将其设置为相对于这NavController整体框架。我想要图像居中的位置是基于在屏幕上获取触摸事件:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {  
    for (UITouch *touch in touches){
        [self dispatchTouchEvent:[touch locationInView:self]];
    }
}

PS。也许另一个有用的答案是,如果您确实从 UITouch 事件中获取坐标,然后想要使用它来使图像在这些坐标上居中,那么您将在基于 UINavigationController 的 iPhone 中的 UIview 子视图中使用的代码是什么应用程序,这将使图像正确居中......

how do I get the x/y co-ordinates of a UIView origin used within a UINavigationController?

That is I have a UINavigationController iPhone app setup. I push a new view, call it CustomUIView, onto the stack. How can I can the absolute origin (x/y cooridnate) of the CustomView's view, relatieve to the overall iPhone screen? That is, so it shouldn't be 0,0 because it should take into account the navigationbar at the top etc.

I note that I get:
* for NavController: frame = (0 0; 320 480)
* for customViewController.view: frame = (0 0; 320 416)
* for customView itself: frame = (0 0; 320 396)

So like the trouble is, when I'm in the customView code itself, and I get it's frame, it gives me 0,0 for origin...

Background: I'm trying to position an image centered at a location on the customView, but it seems to be offset, and I'm guessing because when I'm trying to set it's position relative to the customView, perhaps I should be setting it relative to the NavController overall frame. The position I want the image centered at is based on getting a touch event on the screen:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {  
    for (UITouch *touch in touches){
        [self dispatchTouchEvent:[touch locationInView:self]];
    }
}

PS. Perhaps another helpful answer would be, if you do get co-ordinates from a UITouch event, then want to use this to center an image on these coordinates, what would be the code you would use within a UIview subview, within a UINavigationController based iPhone app, that would center the image properly....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

╰ゝ天使的微笑 2024-12-12 04:44:45

CGPoint ConvertPoint = [self.view.superview ConvertPoint:self.view.frame.origin toView:nil];

请参阅convertPoint:toView的文档:
http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/convertPoint:toView

CGPoint convertedPoint = [self.view.superview convertPoint:self.view.frame.origin toView:nil];

See the documentation for convertPoint:toView:
http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/convertPoint:toView:

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