在我的应用程序的 iPad 版本中,我有一个 UIView
,TPKeyboardAvoidingScrollView
的 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/