Question

I have an existing iPad app (XCode 4.6, iOS 6.2, ARC and Storyboards). It is currently in the App Store in Portrait mode only; I have had several requests for landscape mode. Unfortunately, all of the lines, etc are drawn using CG methods, controlled mathematically. This is what it looks like in portrait mode:

portrait mode

and this is what it looks like in landscape mode:

landscape mode

My question is: where can I find some good docs that will give me the basic steps I need to convert this app for both modes, knowing that the drawing is controlled mathematically?

Was it helpful?

Solution

If it is controlled mathematically, the best way is to refer all coordinates to the dimensions of the parent view, specifically to the property self.view.bounds that changes with the rotation of the device.

Then you have to redraw the interface when the orientation has been changed. A good way to do it is inside the method:

-(void)viewWillLayoutSubviews

If did some custom views in the past with CG methods and the best way is to refer everything to the bounds. In that way when you change the screen size, either by rotating or by using it on the iPhone it works without modifications.

update Imagine that you have a point at (76.8, 512.0) this is precisely in an iPad and portrait orientation, a 10% of the width and a 50% of the height. So for every pair of coordinates instead of using them with absolute numbers you have to replace them by fractions of the dimensions of the parent view:

// old drawing method
CGPoint oldPoint = CGPointMake(76.8, 512.0);

// new drawing method
CGFloat W = self.view.bounds.size.width;
CGFloat H = self.view.bounds.size.height; 
CGPoint newPoint = CGPointMake(0.1 * W, 0.5 * H)  // 76.8 = 0.1 * 768; 512 = 0.5 * 1024

In this second case; when you change the orientation so will the bounds change and the coordinate will get new values, but the proprotion will be the same as in the other orientation, 10% in horizontal and 50% in vertical.

You get the idea.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top