iPhone横向应用程序视图轴混淆

6
使用此处提供的信息:iPhone Landscape-Only Utility-Template Application,我能够启动、使用和维护我的横屏视图。然而,我对坐标轴感到困惑。
绝对坐标轴的行为符合预期,即(0,0)是左上角,(240,0)是顶部中心,(0,320)是左下角等。然而,当我尝试进行与正在绘制的视图相关的计算时,我发现x,y的方向好像以竖屏左上角为原点。因此,要在我的视图控制器中绘制中心点,我需要执行以下操作:
CGPoint center = CGPointMake(self.view.center.y, self.view.center.x);

我认为这是因为我的控制器自身引用的UIView相对于其包含框架(也就是窗口)给出了它的值,而该窗口在纵向模式下具有以左上角为轴原点的坐标系。您是否有什么简单的方法来解决这个问题呢?
文档中建议使用transform属性,但我在这里遇到了更多的困惑。有3个基本属性涉及到此处:
- frame - bounds - center 如果我在viewDidLoad中进行如下操作:
// calculate new center point
CGFloat x = self.view.bounds.size.width / 2.0;
CGFloat y = self.view.bounds.size.height / 2.0;
CGPoint center = CGPointMake(y, x);

// set the new center point
self.view.center = center;

// Rotate the view 90 degrees counter clockwise around the new center point.
CGAffineTransform transform = self.view.transform;
transform = CGAffineTransformRotate(transform, -(M_PI / 2.0));
self.view.transform = transform;

根据参考文档,如果未将transform设置为identity transform,则self.view.frame未定义。因此,我应该使用bounds和center。
现在self.view.center是正确的,因为我将其设置为所需值。self.view.bounds似乎没有改变。self.view.frame似乎正是我想要的,但如上所述,参考文献声称它无效。
因此,虽然我可以获得我认为是正确的数字,但我担心我正在忽略一些关键问题,这些问题以后可能会带来麻烦。
谢谢。
1个回答

2

谢谢你的回答,但根据iPhone应用程序开发指南中关于视图几何的部分:http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40007072-CH8-SW5 你所指出的并不是问题。 - Kevin McAllister
1
如果您继续阅读,它会说:“尽管Quartz使用的坐标系统不使用左上角作为原点,但对于许多Quartz调用,这不是问题。[...]只有在使用Quartz自己设置绘图环境时,您才需要考虑这些不同的坐标系统。”如果您正在使用Quartz手动绘制屏幕内容,那就是答案 :) - Julio Gorgé

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接