在IPHONE 6上重新定位视图时不受约束的约束

时间:2014-12-23 12:52:17

标签: ios objective-c iphone

我使用以下代码在转到横向时向上移动我的视图:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)&&
   !UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
    NSLog(@"Going LandScape");
    self.view.frame = CGRectOffset(self.view.frame, 0, -20);
    //self.view.frame = CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height);
}
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
    NSLog(@"Going Portrait");
    self.view.frame = CGRectOffset(self.view.frame, 0, 20);
}

}

在除iPhone 6(及其外)魔鬼创建之外的所有设备上,它按预期工作,菜单栏保持约束,高于20点(视图结束处)并且在横向底部看起来像这样: landscape, all devices but iphone6

现在在iPhone 6上: landscape on iPhone 6/6plus

注意,我的菜单栏放在一个限制在superview底部的视图中。我试着在绝望中将此代码添加到viewDidLayoutSubviews:

    NSLayoutConstraint *bottomSpaceConstraint = [NSLayoutConstraint constraintWithItem:self.footerView
                                                                         attribute:NSLayoutAttributeBottom
                                                                         relatedBy:NSLayoutRelationEqual
                                                                            toItem:self.view
                                                                         attribute:NSLayoutAttributeBottom
                                                                        multiplier:1.0
                                                                          constant:0.0];
[self.view addConstraint:bottomSpaceConstraint];

也没有做任何事情。

请注意,在iPhone 6上,在菜单栏后面显示20点差距,因此它基本上不尊重约束。我不知道为什么这只会发生在iPhone 6上。任何人都可以帮我解决这个问题吗?提前谢谢!

0 个答案:

没有答案