自动调整大小无法以编程方式工作 [英] Autoresizing Not Working Programmatically
问题描述
我想创建一个UIView
,它将根据iPhone屏幕尺寸调整其宽度,并且应将其保留在视图底部.
I want to create a UIView
which will resize it's width according to iPhone Screen size and it should be remain at bottom of view.
我使用情节提要创建了一个新项目,并添加了以下代码.
I created fresh project with storyboard and add below code.
这是我的代码
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:true];
UIView *box = [[UIView alloc]initWithFrame:CGRectMake(0, 448, 320, 120)];
[box setBackgroundColor:[UIColor redColor]];
[box setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[box setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[box setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
[box setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
[box setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
[self.view addSubview:box];
}
自动布局已关闭.
如果我通过应用界面生成器中的自动调整大小功能来做同样的事情,那么它工作得很好.
If I do same thing by apply autoresizing from interface builder then it's working perfectly.
我不明白为什么它不起作用.
I didn't understand any reason for why it's not working.
推荐答案
从我这边的小错误. 我的代码是正确的.
Little mistake from my side. My code is correct.
问题与xCode 6.1有关,在启动屏幕中,我们具有xCode 6中的xib文件,因此我必须从常规设置"->应用程序图标"和启动图像"中删除对它的引用,并使用断言目录而不是launchscreen.xib及其它开始工作....
The issue is related to xCode 6.1, in launch screen we have xib file from xCode 6 so i have to remove reference of it from General Setting-> App Icon and Launch Images and use Assert Catalog instead of launchscreen.xib and it start working....
无论如何,感谢您对我的问题的答复.
Anyway thanks for reply to my question.
这篇关于自动调整大小无法以编程方式工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!