Search code examples
iphoneobjective-ccocoa-touchuiviewxcode4

Co-ordinates of the four points of a uiview which has been rotated


Is it possible to get this? If so, can anyone please tell me how?


Solution

  • CGPoint topLeft = view.bounds.origin;
    topLeft = [[view superview] convertPoint:topLeft fromView:view];
    
    CGPoint topRight = CGPointMake(view.bounds.origin.x + view.bounds.width, view.bounds.origin.y);
    topRight = [[view superview] convertPoint:topRight fromView:view];
    
    // ... likewise for the other points
    

    The first point is in the view's coordinate space, which is always "upright". Then the next statement finds the point that point corresponds to in the parent view's coordinate space. Note for an un-transformed view, that would be equal to view.frame.origin. The above calculations give the equivalent of the corners of view.frame for a transformed view.