我在带有UIImageView和UILabel的Tab Bar Controller中有一个视图。我定位了UILabel,这样文本就会出现在UIImageView的心脏中。图像视图占据了整个视图。我使用AutoLayout来定位所有内容,并设置为旋转时将图像拉伸以填充整个屏幕,但我遇到了将UILabel放在需要的位置的问题。AutoLayout不能在UILabel上工作
我试着将顶部粘贴到SuperView,但是这会导致UILabel太低,并且固定到底部会在旋转时将UILabel推出视图。这是显示第一件事的图像。
更新:我曾尝试下面的代码,但没有成功:
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"Landscape left");
label1.frame = CGRectMake(29, 20, 509, 142);
[label1 setFrame:CGRectMake(29, 20, 509, 142)];
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"Landscape right");
label1.frame = CGRectMake(29, 20, 509, 142);
[label1 setFrame:CGRectMake(29, 20, 509, 142)];
} else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
NSLog(@"Portrait");
[label1 setFrame:CGRectMake(29, 77, 61, 142)];
}
}
我试过这个,但在'self.view addConstraint'我没有找到topConstraintForView的类方法。 – user717452
@ user717452,你将不得不按照我的方式添加类别。我已经更新了我的答案,以向您展示如何在不添加类别的情况下执行此操作。 – rdelmar
太棒了!谢谢你! – user717452