Question

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

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top