ios - 了解 UIView 和对象的缩放尺寸

标签 ios uitableview uiview uiviewcontroller autoresizingmask

我试图更好地理解如何根据旧款 iphone 和新 iphone 的尺寸差异来控制 View 的尺寸。

如果我有如下例所示的设计,应该如何根据 subview 以编程方式进行编码。

Example

请原谅图表绘制得不好,但它应该有助于解释。

在这个例子中,fieldView和buttonView总是需要保持固定的大小,因为它们的对象在变小时看起来不太好。然而, Logo View 有另一个 Logo 本身的 subview ,因此可以根据设备/屏幕尺寸进行缩小。

这将如何实现?以编程方式设置示例 subview 。我不明白的部分是,在创建 subview 的 viewDidLoad 中,您是否不必按如下顺序创建:

-(void)ViewDidLoad {
CGRect screen = [[UIScreen mainScreen] applicationFrame];
wholeView = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, self.view.bounds.size.height)];

 logoView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,150);
fieldView = [[UITableView alloc] initWithFrame:CGRectMake(0, logoView.bounds.size.height, 320, 100);

我了解如何使用

autoresizingMask

但是它如何根据可用的实际 View 尺寸来计算高度呢?

最佳答案

不确定我是否理解您的疑虑,但添加以下内容应该可以解决问题:

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
logoView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

剩余的 View 将保持其边距和高度/宽度固定(即,其autoresizingMaskUIViewAutoresizingNone的默认值就可以了。)

how would it come into use in terms of working out a height depending on the actual view size available?

基本上,您在 iPhone 显示屏上看到的是 View 层次结构;此层次结构中最顶层的 View 是 UIWindow。它与设备屏幕的大小相同(它是这样初始化的)。

现在,在上面的代码中,我们的 logoView 具有固定的边距:这意味着它将与容器 View 框架保持相同的距离;如果我们指定尺寸是灵活的,那么 logoView 将简单地占据整个空间以保持边距固定。

关于ios - 了解 UIView 和对象的缩放尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15005048/

相关文章:

ios - Thread 1 : EXC_BAD_ACCESS (code=1, address=0x20) 当subView

ios - swift 3 使用图层通过绘制 "clear"行来显示图像

ios - 如何在时间后停止 DispatchGroup? iOS

ios - UISegmentedControl 在 UITableView 标题上的行为方式很奇怪

ios - CloudKit fetchRecordWithID 错误 : "Fetching asset failed"

ios - 从另一个 UIViewController 的 UITableView 获取 UITableViewCell

ios - 如何使用drawRect重写获得UIView子类的某些区域的透明度

iphone - 重叠的 UITextView 边框

ios - 循环字典中的特定键以获取值

ios - UITableView 分隔线被添加到节标题 View ,怎么办?