简体   繁体   English

在ib中布置应用时,格式与模拟器中的格式不同

[英]Formatting is different when laying out app in ib than in simulator

I am just learning how to make apps and the first thing I noticed is when I graphically lay out my application in interface builder it is not the same when I run it in the simulator or on my own device. 我只是在学习如何制作应用程序,而我注意到的第一件事是,当我在界面生成器中以图形方式对应用程序进行布局时,当我在模拟器或自己的设备上运行该应用程序时,情况有所不同。 I have two screen shots of what is happening.. 我有两个正在发生的屏幕截图。

在界面构建器中

在模拟器上

Notice the space between the segment and the switches... they are different and it causes problems when I want to move the switches up... 注意段和开关之间的空间...它们是不同的,当我想向上移动开关时会引起问题...

How can I fix this? 我怎样才能解决这个问题? It looks like maybe to have to do with the larger screen size of newer iphone and that is not what is running in my simulator... If so what are some things I should know when designing apps that look good on both phones? 看起来可能与更新的iPhone的更大屏幕尺寸有关,而这并不是我的模拟器中正在运行的内容...如果是这样,那么在设计两部手机上看起来都不错的应用程序时我应该知道些什么?

The issue, as I think you diagnosed, is that Interface Builder is showing you the 4" screen, but your simulator is showing you the 3.5" screen. 正如我认为您所诊断的,问题是Interface Builder向您显示4“屏幕,而您的模拟器向您显示3.5”屏幕。 In Interface Builder you can click on the following button in the lower right corner of the main panel to toggle between 4" and 3.5" display: 在Interface Builder中,您可以单击主面板右下角的以下按钮在4“和3.5”的显示之间切换:

切换iPhone屏幕尺寸

You can also, in the simulator, choose your "device" to be either a 3.5" screen or a 4" screen from the "Hardware" menu, too, so you can simulate running your app on both size app screens. 您也可以在模拟器中,从“硬件”菜单中将“设备”选择为3.5英寸屏幕或4英寸屏幕,以便可以模拟在两个大小的应用程序屏幕上运行应用程序。 By the way, when you go to a "retina" simulator, it will appear twice as large on the screen (because the screen has twice the resolution). 顺便说一句,当您进入“视网膜”模拟器时,它将在屏幕上显示两倍大(因为屏幕的分辨率是原来的两倍)。 But you can control the size of the simulator window by playing around with the "Scale" options on the simulator's "Window" menu. 但是您可以通过在模拟器的“窗口”菜单上使用“缩放”选项来控制模拟器窗口的大小。 This just changes the size of the simulator's rendition of the simulated device on your Mac's screen. 这只是改变了Mac屏幕上模拟器对模拟设备的再现大小。 But if you're working on a smaller Mac screen, sometimes you'll find this "Scale" option useful, too. 但是,如果您使用的是较小的Mac屏幕,有时您会发现此“缩放”选项也很有用。

But you really want to make sure your app works well, regardless of the size of the screen, so you really should test the app for both sizes. 但是您确实想确保您的应用程序运行良好,而不管屏幕的大小如何,因此您确实应该针对这两种尺寸测试应用程序。 You want your app to render nicely on both iPhone 4 devices as well as iPhone 5 devices. 您希望您的应用程序在iPhone 4设备和iPhone 5设备上都能很好地呈现。 Fortunately, you can achieve this with a single storyboard. 幸运的是,您可以使用单个情节提要板实现此目的。

In terms of what dictates the layout of your controls on the two sizes of screens, it depends upon whether you're using auto layout or not. 在决定在两种尺寸的屏幕上控件布局的因素方面,这取决于您是否使用自动布局。 You control that by clicking on the first tab of that far right panel and checking or unchecking the "use autolayout" checkbox: 您可以通过单击最右侧面板的第一个选项卡,然后选中或取消选中“使用自动布局”复选框来控制它:

自动布局

If not using autolayout (which is important if your app is to run on iOS 5, for example), you can go to the autosizing mask tab and control the "springs and struts" that dictate the layout. 如果不使用自动布局(例如,如果您的应用程序要在iOS 5上运行,则这很重要),则可以转到“自动调整大小的蒙版”选项卡,并控制决定布局的“弹簧和支柱”。 For example, if you click on one of your controls in your scene, you can then control whether the margins should change as the size changes, or whether the layout should, by looking at the "size inspector" tab: 例如,如果您单击场景中的一个控件,则可以通过查看“尺寸检查器”选项卡来控制边距是否应随尺寸的变化而变化,或者布局是否应随尺寸的变化而变化:

弦和支柱

If you hover over that "example" window, it will animate how the size will change as the size of its superview does (eg whether the iPhone has a 3.5" screen or a 4" screen). 如果将鼠标悬停在该“示例”窗口上,它将动画化其大小随其超级视图的大小变化的方式(例如,iPhone是具有3.5英寸的屏幕还是4英寸的屏幕)。

On the other hand, if you're using autolayout (which works on devices running iOS 6 and higher, only), the layout on the screen is dictated by the "constraints" you have defined for the view (see the latter half of the image below): 另一方面,如果您使用的是自动布局(仅适用于运行iOS 6及更高版本的设备),则屏幕上的布局取决于您为视图定义的“约束”(请参见后半部分)。下图):

自动布局

If you want to have perfect control over the layout you should have 2 different XIBs, one for the standard screen (320 x 480) and another one for the new iPhone 5 screen (320 x 568). 如果要完全控制布局,则应该有2种不同的XIB,一种用于标准屏幕(320 x 480),另一种用于新iPhone 5屏幕(320 x 568)。 That way you can specify exactly where each element will appear and you won't have any surprises with different screen sizes. 这样,您可以准确指定每个元素的显示位置,并且在屏幕尺寸不同的情况下也不会感到惊讶。

But in any case you should always leave the anchoring and autoresizing of each element you put into your XIB well configured. 但是无论如何,您都应该始终将放置在配置良好的XIB中的每个元素的锚定和自动调整大小。

The following is from this tutorial . 以下是本教程的内容

When the screen rotates on an iOS device you can manage how the UI objects will alter their position or if they stretch to fill the new window. 当屏幕在iOS设备上旋转时,您可以管理UI对象如何更改其位置或它们是否伸展以填充新窗口。 This can all be managed with this simple little tool in Interface Builder. 所有这些都可以通过Interface Builder中的这个简单的小工具进行管理。

在此处输入图片说明

The box on the left is where you decide how the object will scale and the box on the right is an animated visualisation on how the object will perform when the layout frame is modified. 左边的框是您决定对象缩放比例的地方,右边的框是动画视图,显示了修改布局框架时对象将如何执行。 The outer box on the left is where you set the “anchors” or what sides the object will lock on. 左侧的外框是您设置“锚”或对象将锁定在哪一侧的位置。 Any side selected will make the object stick to that side when the screen dimensions change. 屏幕尺寸更改时,所选的任何一侧都会使对象粘附到该侧。 The inner square has controls for stretching. 内部正方形具有用于拉伸的控件。 When the object is locked on 2 sides and the screen changes its width then the object can be told to stretch with the screen. 当对象锁定在两侧时,屏幕会改变其宽度,然后可以告知对象与屏幕一起拉伸。 Its worth having a play with these settings and see the results from different configurations. 值得一试的是这些设置,并查看不同配置的结果。

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

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