Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone landscape-only app view axis confusion

Using the information here: iPhone Landscape-Only Utility-Template Application I am able to launch, use and maintain my view as landscape only. However, I am confused about the axis.

The absolute axis behaves as expected, meaning (0,0) is the top left, (240,0) is the top center, (0,320) is the bottom left corner, etc. However, when I attempt to do calculations related to the view I am drawing on I find x,y to be oriented as if the portrait top left were the origin. So to draw something at the center-point in my view controller I need to do:

CGPoint center = CGPointMake(self.view.center.y, self.view.center.x);

I assume this due to the fact that the UIView referenced by my controllers self.view is giving it's values relative to it's enclosing frame, meaning the window which has it's axis origin on the top left in portrait mode.

Is there some simple way to account for this that I am missing?

Documentation suggests that the transform property is exactly what I am looking for, however, I experiencing further confusion here. There are 3 essential properties involved:

  • frame
  • bounds
  • center

If I do this in 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;

Now according to the reference docs, if transform is not set to the identity transform self.view.frame is undefined. So I should work with bounds and center.

self.view.center is correct now, because I set it to what I wanted it to be. self.view.bounds appears unchanged. self.view.frame appears to be exactly what I want it to be, but as noted above, the reference claims it is invalid.

So while I can get what I believe to be the right numbers, I fear I am overlooking something critical that will become troublesome later.

Thanks.

like image 412
Kevin McAllister Avatar asked Apr 10 '09 16:04

Kevin McAllister


1 Answers

With Quartz 2D, the coordinate system has its origin (0,0) at the lower-left corner of the graphic, not at the upper-left corner. Maybe that's what you are missing.

See: http://developer.apple.com/documentation/graphicsimaging/Conceptual/drawingwithquartz2d/dq_overview/dq_overview.html#//apple_ref/doc/uid/TP30001066-CH202-CJBBAEEC

like image 200
Julio Gorgé Avatar answered Oct 11 '22 17:10

Julio Gorgé