在基于视图的iPhone OS应用程序,我改变从初始纵向取向到的横向(UIInterfaceOrientationLandscapeRight)。但现在的X,Y原点(0,0)是在左下角(而不是通常的左上方),每次我想要做的事,涉及到的坐标我必须重新计算以补偿新的坐标系。我也注意到,新的坐标系内我的意见没有有时表现正常。那么,有没有一种方法,坐标系统转换一次,之后我转了方向,这样我可以保持我的坐标的思维具有在左上角原点?

有帮助吗?

解决方案

如果你申请的推荐方法一以旋转其转换成你的主要观点:

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;
}   

然后添加到此主视图中的任何的子视图应使用标准坐标系。施加到主视图需要旋转所述子视图的坐标的护理,以及变换。这很适合我在我的应用程序。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top