【发布时间】:2011-12-20 09:13:34
【问题描述】:
我有一个尺寸为 width=320px height=40px 的 UIView,我想在底部显示它,看起来像一个标签栏。
我使用以下代码来完成此操作,它在 iPhone 上运行良好。但是当我尝试 iPad 模拟器时,视图并没有出现在屏幕上的任何位置。
buttonsView.frame=CGRectMake(
0,
self.view.frame.size.height - buttonsView.frame.size.height,
self.view.frame.size.width,
buttonsView.frame.size.height );
这会将视图拉伸到屏幕的宽度,但保持其原始高度。
我怎样才能在我的 iPad 上也制作这个节目?
[更新]
这发生在我的viewDidLoad。
我现在有这个 NSLog:
NSLog(@"buttonsView Width: \t%g\t%g\tHeight:\t%g\t%g",self.view.frame.size.width, buttonsView.frame.size.width, self.view.frame.size.height, buttonsView.frame.size.height);
带输出:
iPhone:
按钮视图宽度:320 320 高度:460 40
iPad:
按钮视图宽度:768 768 高度:1004 40
我还为页面顶部创建了另一个这样的视图,效果很好:
dataView.frame=CGRectMake(
0,
0,
self.view.frame.size.width,
dataView.frame.size.height);
【问题讨论】:
-
这段代码什么时候被调用?在
init、viewDidLoad、viewWillAppear等?