简体   繁体   English

转换iPad应用程序以处理两种视图模式的最佳方法是什么?

[英]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). 我有一个现有的iPad应用程序(XCode 4.6,iOS 6.2,ARC和情节提要)。 It is currently in the App Store in Portrait mode only; 目前,它仅在App Store中处于纵向模式; I have had several requests for landscape mode. 我对横向模式有一些要求。 Unfortunately, all of the lines, etc are drawn using CG methods, controlled mathematically. 不幸的是,所有的线等都是使用CG方法绘制的,并且受到数学控制。 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. 如果以数学方式进行控制,则最好的方法是将所有坐标引用到父视图的尺寸,尤其是引用随设备旋转而变化的属性self.view.bounds。

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. 如果过去使用CG方法进行过一些自定义视图,则最好的方法是将所有内容都引用到边界。 In that way when you change the screen size, either by rotating or by using it on the iPhone it works without modifications. 这样,当您通过旋转屏幕或在iPhone上使用它来更改屏幕尺寸时,它无需修改即可工作。

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. 更新想象一下,您在(76.8,512.0)处的点正好是iPad和纵向方向,宽度为10%,高度为50%。 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. 当更改方向时,边界也会更改,并且坐标将获得新值,但是比例将与其他方向相同,水平方向为10%,垂直方向为50%。

You get the idea. 你明白了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 处理iPad / iPhone视图的最佳方法是什么? - What is the best way to handle iPad/iPhone views? 在ipad应用程序中处理许多ASIHttpRequests和核心数据操作的最佳方法 - Best way to handle many ASIHttpRequests and core data operations in ipad app 在用户首次打开应用程序时处理登录屏幕的最佳方法是什么? - What's the best way to handle showing a sign in screen the first time a user opens an app? 在iPad上浏览照片的最佳方法是什么? - What is the best way to thumb through photos on the iPad? iPad应用程序存储数据的最佳方法是什么 - What is the best method to store data for an iPad app 在视图控制器之间进行反向通信的最佳方法是什么? - What's the best way to reverse communicate between view controllers? 轮换后在视图中重组元素的最佳方法是什么? - What's the best way to reorganize elements in a view after rotation? 在iPad应用程序中维护Wikitext和RTF编辑模式 - maintaining wikitext and richtext editing modes in iPad app 视图控制器之间通信的最佳方式是什么? - What's the best way to communicate between view controllers? 什么是在Mac应用程序中“捆绑”宝石的最佳方法? - What's the best way to 'bundle' a gem inside a Mac app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM