开发者

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

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....


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:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜