ios - xib 和代码之间具有不同高度的 UIView

标签 ios xcode uiview xib

在我的应用程序的 iPad 版本中,我有一个 UIViewTPKeyboardAvoidingScrollView 的 subview ,由 xib 创建,它的框架(0.0, 1024, 437)。当您在输出框架中运行应用程序时,它相应地变为 (0.0, 1024, 800),其高度几乎是应有的两倍。这是什么意思?我该如何解决?

代码:

   //self.scrollView is a TPKeyboardAvoidingScrollView

   CGFloat width = self.scrollView.frame.size.width;//is correct
   CGFloat progY = 0;

    self.view1.frame = CGRectMake(0, progY, width, 
                          self.view1.frame.size.height);
    [self.scrollView addSubview:self.view1];

    progY+= self.view1.frame.size.height;
   //is correct, the height is equal to that of the xib

    self.view2.frame = CGRectMake(0, progY, width, self.view2.frame.size.height);
    NSLog(@"the frame of view2 is %@", NSStringFromCGRect(self.view2.frame));
    //the frame of view2 is {{0, 215}, {1024, 800}}
    //the height would be 437 as in xib

    [self.scrollView addSubview:self.view2];

    progY+= self.view2.frame.size.height;//is wrong

    //....

最佳答案

您的 XIB 中的基本 View 可能具有错误的自动调整属性等。

在 Size Inspector 中查看基本 View 的自动调整大小设置 - 它不应连接到屏幕的下端,也不应动态更改高度,这样就没问题了。

关于ios - xib 和代码之间具有不同高度的 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16957232/

相关文章:

ios - 当使用 Parse 查询数据时,我的 View 仅在重复 while 之后加载

ios - 自动布局前导和尾随约束(动画)

iphone - 处理 iPhone 3.5inch 和 iPhone 4inch 显示屏 (UIScrollView)

ios - 我应该使用哪个高级 API 来管理 iOS 上的 UDP 套接字?

javascript - 将 js 输出转换为 Objective-C

ios - 用动画颜色填充 UIView 的一部分

ios - 如何在带有 UITableView.automaticDimension 的 uitableviews 静态单元格中使用 uiscrollview

ios - 没有填充的画圈 IOS

ios - 仅在 TableView 的特定单元格上显示和隐藏 View

swift - 如何在 Swift 中创建直角 View ?