有没有办法在更改为横向方向后转换坐标系?

Rex*_*ids 5 iphone device orientation

在基于视图的iPhone OS应用程序中,我将方向从初始纵向方向更改为横向(UIInterfaceOrientationLandscapeRight).但现在的X,Y原点(0,0)是左下角的角落(而不是通常的左上方),每次我想要做的事,涉及到的坐标,我必须重新计算,以弥补新坐标系统.我也注意到我在新坐标系中的视图有时不正常.那么,有没有办法在我切换方向后立即转换坐标系ONCE,以便我可以一直认为我的坐标在左上角有一个原点?

Bra*_*son 10

如果您采用建议的方法将变换应用于主视图以便旋转它:

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's 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's 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;
}   
Run Code Online (Sandbox Code Playgroud)

那么您添加到此主视图的任何子视图都应使用标准坐标系.应用于主视图的变换也负责旋转子视图的坐标.这在我的应用程序中对我很有用.