简体   繁体   中英

What's the best way to convert iPad app to handle both view modes?

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:

纵向模式

and this is what it looks like in 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM