views:

1678

answers:

1

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.

+1  A: 

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

Julio Gorgé
Thank you for the answer, but according to the iPhone Application Developer Guide section on View Geometry: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40007072-CH8-SW5 what you indicate is not the problem
Kevin McAllister
And if you keep reading it says "Although the coordinate system used by Quartz does not use the top-left corner as the origin point, for many Quartz calls this is not a problem. [...] he only time you need to consider these different coordinate systems is when you set up the drawing environment yourself using Quartz." If you are manually drawing stuff to screen using Quartz, that'd be the answer :)
Julio Gorgé