gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:53:56 25 4
gpt4 key购买 nike

在基于 View 的 iPhone OS 应用程序中,我将方向从最初的纵向更改为横向 (UIInterfaceOrientationLandscapeRight)。但现在 x,y 原点 (0,0) 位于左下角(而不是通常的左上角),每次我想做一些涉及坐标的事情时,我都必须重新-计算以补偿新的坐标系。我还注意到,我在新坐标系中的 View 有时表现不正常。那么,有没有办法在我切换方向后立即转换坐标系,以便我可以继续认为我的坐标原点位于左上角

最佳答案

如果您采用推荐的方法对主视图应用变换以旋转它:

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

那么您添加到该主视图的任何 subview 都应该使用标准坐标系。应用于主视图的变换也负责旋转 subview 的坐标。这在我的应用程序中非常适合我。

关于iphone - 有没有办法在更改横向方向后转换坐标系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/896994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com