我想知道在用固定值在 neb 中设置视图的高度时是否会遇到麻烦。
示例:状态栏的高度是已知的。是20个单位。那么在制作一个界面不错的视图时,当用户在使用 App 时接听电话,并且状态栏的高度增加了会发生什么?或者如果苹果在未来的某一天改变状态栏或标签栏的高度会怎样?
您是否总是为包含所有界面元素的容器视图使用自动调整大小功能?你的模式是什么?
我想知道在用固定值在 neb 中设置视图的高度时是否会遇到麻烦。
示例:状态栏的高度是已知的。是20个单位。那么在制作一个界面不错的视图时,当用户在使用 App 时接听电话,并且状态栏的高度增加了会发生什么?或者如果苹果在未来的某一天改变状态栏或标签栏的高度会怎样?
您是否总是为包含所有界面元素的容器视图使用自动调整大小功能?你的模式是什么?
我会避开程序中状态栏、工具栏等高度的硬编码值。您提供了一些很好的例子来说明这些值是如何动态变化的,并且在未来会发生变化。您可能支持也可能不支持的另一种常见情况是用户将 iPhone 旋转到横向的能力。
我总是尽量保持容器子视图的布局灵活。使用自动调整大小功能是一个好方法。你的问题是一个很好的问题,我认为它会让我重新审视自己的布局策略!
我总是使用自动调整大小的灵活布局,因为这让我可以专注于设计并让计算机计算出数学。
[编辑] 我的原因是有些事情会发生变化,在这种情况下我不想再做数学了。可以改变的事情:
因此,如果您将布局设为静态,您最终将不得不再次这样做。然后再次。直到您了解到软件开发中唯一不变的就是变化。
好吧,我在这里有点冒险,但我认为硬编码布局尺寸的想法(今天,在 iPhone 上,以像素为单位)理论上可能会给你带来麻烦(或者至少需要额外的工作)在将来。
我不太担心它们会改变状态栏、默认标签栏或导航栏的外观大小……我担心单位会发生变化。我不是注册的 OS X 开发人员,但长期以来一直有传言称,Snow Leopard 将支持一种独立于分辨率的方式来指定接口,而不是基于像素。
它不会在明天、3.0 甚至明年发生,但这种独立于分辨率的界面的想法将适用于 iPhone,尤其是在未来显示尺寸(更具体地说,显示分辨率)发生变化时.
我很啰嗦,但我关心的不是状态栏的大小,而是设备的大小,以及我们在 Cocoa Touch 中用于指定大小的单位。
需要考虑的一件事:如果用户接到电话,然后在通话期间启动应用程序,状态栏的高度会发生变化。所以绝对有必要避免在系统 UI 元素的高度进行硬编码。
Theres a "constants.h" in the UICatalog sample, but it's local to that sample and is clearly just a way for the sample developer to make his/her life easier. It carries with it all the problems mentioned above ... if anything changes the "standard sizes" in the future, this sample stops working properly.
It sucks to have to query other objects to get your placement right, but it's how you ensure things work properly when the environment changes. The expanding "in-call" status bar is a perfect example. If you hard-code 20 "units" to avoid the status bar, your app breaks while in a call. And, that's something you're not likely to notice in the simulator (because, if you thought about it enough to try that option in the simulator, you probably would have thought about it while coding the app!)
Apple 提供的文件“Constants.h”中不存在大多数这些大小吗?(我刚刚注意到它是 UICatalog SDK 示例的一部分)。
我认为苹果很可能会在某个时候推出另一款屏幕更大或更小的设备。所以它们应该与 [UIScreen frame/bounds] 一起使用;
// these are the various screen placement constants used across all the UIViewControllers
// padding for margins
#define kLeftMargin 20.0
#define kTopMargin 20.0
#define kRightMargin 20.0
#define kBottomMargin 20.0
#define kTweenMargin 10.0
// control dimensions
#define kStdButtonWidth 106.0
#define kStdButtonHeight 40.0
#define kSegmentedControlHeight 40.0
#define kPageControlHeight 20.0
#define kPageControlWidth 160.0
#define kSliderHeight 7.0
#define kSwitchButtonWidth 94.0
#define kSwitchButtonHeight 27.0
#define kTextFieldHeight 30.0
#define kSearchBarHeight 40.0
#define kLabelHeight 20.0
#define kProgressIndicatorSize 40.0
#define kToolbarHeight 40.0
#define kUIProgressBarWidth 160.0
#define kUIProgressBarHeight 24.0
// specific font metrics used in our text fields and text views
#define kFontName @"Arial"
#define kTextFieldFontSize 18.0
#define kTextViewFontSize 18.0
// UITableView row heights
#define kUIRowHeight 50.0
#define kUIRowLabelHeight 22.0
// table view cell content offsets
#define kCellLeftOffset 8.0
#define kCellTopOffset 12.0
托尼