Is there a way to transform the coordinate system after changing the orientation of the terrain?

In a view-based iPhone OS application, I change the orientation from the initial portrait orientation to landscape orientation (UIInterfaceOrientationLandscapeRight). But now x, y origin (0,0) is in the corner lower left (instead of the usual upper left), and every time I want to do something that includes coordinates, count to compensate for the new coordinate system. I also noticed that my views in the new coordinate system sometimes do not behave normally. So, is there a way to convert the ONCE coordinate system right after switching the orientation so that I can think that my coordinates have the origin in the upper left corner ?

+5
source share
1 answer

If you recommend applying the transform to the main view to rotate it:

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight) 
{
    CGAffineTransform transform = primaryView.transform;

    // Use the status bar frame to determine the center point of the window content area.
    CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
    CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);
    CGPoint center = CGPointMake(60.0, bounds.size.height / 2.0);

    // Set the center point of the view to the center point of the window content area.
    primaryView.center = center;

    // Rotate the view 90 degrees around its new center point.
    transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
    primaryView.transform = transform;
}   

then any subspecies that you add to this main view should use a standard coordinate system. The transformation that applies to the main view also takes care to rotate the coordinates of the subzones. This works well for me in my application.

+10
source

All Articles