一个关于代码编写界面的小问题

小弟最近开发应用时,开始尝试着使用代码来编写界面(之前都是使用的IB),结果在iOS6和iOS7两台机子上却出现了差距有点大的界面效果,如下图:


关键是上面那个button的位置不是我想要的。
两台都是iPhone4
loadview的代码如下:

        self.view = [UIView alloc] initWithFrame:[UIScreen mainScreen] bounds]] autorelease];
    self.view.backgroundColor = [UIColor whiteColor];

    
    self.recordButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.recordButton setTitle:@"Record" forState:UIControlStateNormal];
    [self.recordButton addTarget:self action:@selector(PushAppList) forControlEvents:UIControlEventTouchUpInside];
    [self.recordButton setBackgroundColor:[UIColor blueColor]];
    self.recordButton.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:self.recordButton];
    
    
    
    self.playButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.playButton setTitle:@"Play" forState:UIControlStateNormal];
    [self.playButton addTarget:self action:@selector(PushScriptList) forControlEvents:UIControlEventTouchUpInside];
    [self.playButton setBackgroundColor:[UIColor blueColor]];
    self.playButton.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:self.playButton];
    
    
    
    NSLayoutConstraint *recordButton_contraint_v = [NSLayoutConstraint constraintWithItem:self.recordButton attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0];
    
    NSLayoutConstraint *recordButton_contraint_h = [NSLayoutConstraint constraintWithItem:self.recordButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0f constant:60];
    
    
    NSLayoutConstraint *playButton_contraint_v = [NSLayoutConstraint constraintWithItem:self.playButton attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0];
    
    NSLayoutConstraint *playButton_contraint_h = [NSLayoutConstraint constraintWithItem:self.playButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0f constant:-80.0f];
    
    NSLayoutConstraint *playButton_contraint_width = [NSLayoutConstraint constraintWithItem:self.playButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.recordButton attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0];
    
    [self.view addConstraints:@[recordButton_contraint_v,recordButton_contraint_h,playButton_contraint_h,playButton_contraint_v,playButton_contraint_width]]

就说上面的那个button,我设置的垂直方向的Constraint是离self.view的顶部的距离为60,但是iOS6和iOS7上,第一个button离顶部的距离明显是不同的

你只说了你不想要的结果,却没有说你想要的结果。你只给出了代码,而没有给出你的分析、思考过程,你觉得出现这种问题的可能原因等等。建议把帖子的逻辑整理好,把问题想清楚了再编辑一下

解决了,是因为我的self.view初始化成[UIScreen mainScreen] bounds了,换成[UIScreen mainScreen] applicationFrame]就可以了。

iOS 6和7对status bar和navigation bar的定义不一样了,应该是这个地方出的问题