简体   繁体   English

如何以及何时调整子视图的位置?

[英]How and when to adjust the position of subviews?

I have created the layout of my main view in a xib-file, but I want to adjust it somewhat in runtime. 我已经在xib文件中创建了主视图的布局,但是我想在运行时进行一些调整。

I call my adjusting code from viewDidAppear. 我从viewDidAppear调用调整代码。 The code sets the upper left corner of a button to (0,0), but the button becomes partly hidden by the status bar! 该代码将按钮的左上角设置为(0,0),但是状态栏部分隐藏了该按钮!

(I call the same code when the veiw rotates and then it works fine!) (当面纱旋转时,我调用相同的代码,然后它可以正常工作!)

Can someone explain this? 有人可以解释吗?

code snippet: 代码段:

-(void) viewDidAppear:(BOOL) animated{
    [super viewDidAppear:animated];

    CGRect rc = CGRectMake(0, 0, 128, 128);
    [buttBack setFrame:rc];

}//viewDidAppear

Put some dummy buttons at the 4 angles of your view. 在视图的4个角度放置一些虚拟按钮。 When runned, you wil be able to see if they disapear partially out of the screen / under the tool bar. 运行后,您将能够看到它们是否部分消失在屏幕外/工具栏下方。 If yes, that would explain why setting 0/0 for the origin of your button does the same thing. 如果是,那将解释为什么将按钮的原点设置为0/0会产生相同的结果。

Also, check that the view that contains the button you want to adjust has all its auto-adjust properties well defined. 另外,检查包含要调整的按钮的视图是否已正确定义其所有自动调整属性。 Verify also that "toolbar" simulation is ON on the main view into your XIB. 还要确认进入XIB的主视图中的“工具栏”模拟已打开。

After having done that, check also that your view's H and W are correct (not too big nor loaw), but this is just for conscience, having adjusted the auto-adjust properties should deal with such errors. 完成此操作后,还请检查视图的H和W是否正确(不要太大或不松动),但这只是出于良心,调整自动调整属性应该可以处理此类错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM