Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用自动布局以编程方式创建UIViewController_Ios_Objective C_Uiviewcontroller - Fatal编程技术网

Ios 使用自动布局以编程方式创建UIViewController

Ios 使用自动布局以编程方式创建UIViewController,ios,objective-c,uiviewcontroller,Ios,Objective C,Uiviewcontroller,我想创建一个具有自动布局按钮的UIViewController。(与WWDC 2012会话202中相同)此视图控制器在UINavigationController中推送 我根本不想使用故事板。一切都必须以编程方式完成 问题是如何设置视图控制器的主视图的尺寸,使其具有屏幕大小 我的视图控制器如下所示: @EAViewController的实现 -(无效)viewDidLoad { [超级视图下载]; self.view.backgroundColor=[UIColor blueColor]; UI

我想创建一个具有自动布局按钮的UIViewController。(与WWDC 2012会话202中相同)此视图控制器在UINavigationController中推送

我根本不想使用故事板。一切都必须以编程方式完成

问题是如何设置视图控制器的主视图的尺寸,使其具有屏幕大小

我的视图控制器如下所示:

@EAViewController的实现
-(无效)viewDidLoad
{
[超级视图下载];
self.view.backgroundColor=[UIColor blueColor];
UIView*superview=self.view;
UIButton*button=[UIButton button类型:UIButtonyPeroundRect];
[按钮设置标题:@“按钮”用于状态:uicontrol状态正常];
[超级视图添加子视图:按钮];
NSLayoutConstraint*cn=[NSLayoutConstraint constraintWithItem:按钮
属性:nsLayoutAttributeCenter
关系人:NSLayoutRelationEqual
toItem:self.view
属性:nsLayoutAttributeCenter
乘数:1.0
常数:0.0];
[self.view addConstraint:cn];
cn=[NSLayoutConstraint constraintWithItem:按钮
属性:NSLAYUTATTRIBUTEBOTTOM
关系人:NSLayoutRelationEqual
toItem:self.view
属性:NSLAYUTATTRIBUTEBOTTOM
乘数:1.0
常数:-20];
[self.view addConstraint:cn];
[self.view set translates自动调整大小GMaskintoConstraints:否];
[按钮设置翻译自动调整大小GMaskintoConstraints:否];
}
@结束
我在App Delegate中这样推它

-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
//没有故事板
self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
EAViewController*viewController=[[EAViewController alloc]init];
UINavigationController*导航控制器=[[UINavigationController alloc]initWithRootViewController:viewController];
navigationController.view.backgroundColor=[UIColor whiteColor];
self.window.rootViewController=navigationController;
[self.window makeKeyAndVisible];
//应用程序启动后自定义的覆盖点。
返回YES;
}   
结果是按钮没有正确的Y偏移。
如果我在不使用导航控制器的情况下直接按下视图控制器,它会工作。

我怀疑您的y偏移量与导航栏(48)的偏移量相同,因为iOS 7现在全屏显示,即在导航栏下方向上,所以这是正常行为