2

我的 GLKViewController 子类中有一些看起来像这样的代码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch * touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];
    NSLog(@"touch has begun!: %f %f",point.x,point.y);
    float xw = [self.view bounds].size.width;
    float yw = [self.view bounds].size.height;
    NSLog(@"touch -- %f %f", point.x / xw, point.y / yw);
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationLandscapeRight == toInterfaceOrientation;
}

此外,我在“iPhone/iPod 部署信息”中将唯一支持的设备方向设置为“横向”。

通过运行上面的代码进行测试,它看起来好像左上角是 (0,0)。但是,我有另一个与此类似的测试项目,其中 (0,0) 点位于左下角。

究竟是什么决定了坐标系的方向?如果我希望我的 (0,0) 点位于左下角而不是左上角,我该怎么做?

4

1 回答 1

2

在 iOS 上,(0,0) 处的角(称为原点)应始终位于左上角。我不知道有没有一种方便的方法来更改它,除了可能将 UIView 子类化并处理所有各种算术 - 计算你的边界/框架,布置你的子视图和绘制你的内容 - 你自己。

在 Mac 上,原点略有不同:默认位于左下角。但是,您可以继承 NSView 并YES从该-isFlipped方法返回,以向视图层次结构表明您希望您的坐标表现得像 iOS,原点位于左上角。

我不知道有什么简单的方法可以让您意外地在 iOS 的左下角看到原点。如果您发布其他测试项目中的一些代码,我可以扩展这个答案来解决它。

于 2012-09-19T20:08:58.703 回答