我在故事板中有以下视图。肖像版本正常工作没有任何问题。但我想在景观视图中缩小Profile Image
。然后底部项目获取屏幕上的空间。做我需要做的编码除自动版式Xcode Autolayout - 使横向视图中的子视图小
人像模式
风景模式
故事板视图
我在故事板中有以下视图。肖像版本正常工作没有任何问题。但我想在景观视图中缩小Profile Image
。然后底部项目获取屏幕上的空间。做我需要做的编码除自动版式Xcode Autolayout - 使横向视图中的子视图小
人像模式
风景模式
故事板视图
您可以使用If-else条件为两个方向手动设置框架。
例如:
if (orientation == UIInterfaceOrientationMaskPortrait)
{
self.view.frame = CGRectMake(0, 0, 1000, 800);
self.tableView1.frame = CGRectMake(1, 0, 764,510);
}
else if (orientation == UIInterfaceOrientationMaskLandscapeLeft)
{
self.view.frame = CGRectMake(0, 0, 1300, 370);
self.tableView1.frame = CGRectMake(0, 0, 1300, 370);
self.view.backgroundColor = [UIColor blackColor];
}
你不应该觉得取向 “风景” 的了。最好将其视为垂直:紧凑型,高度:紧凑型,这对于除6+以外的所有iPhone都是基本上景观的。
选择你想要的大小类。如果你不太了解它们,Xcode会告诉你每一个代码是什么。
控制从UIImageView
拖动到主要UIView
并选择“等宽”并命令点击“等高”。
点击您的UIImageView
。在“实用程序”检测器栏区域(右侧面板)中,单击“标尺”图标,您将看到UIImageView
的约束条件。
调整“等高”和“等宽”限制为视图的百分比。您可能需要根据自己的喜好调整它。
你不需要任何超过Autolayout
来做到这一点。不要直接在viewWillTransitionToSize:coordinator:
中设置框架 - 通过这样做基本上可以对框架尺寸进行硬编码,并且您必须为每个尺寸类别对UITraitCollection
进行大量检查,以便为每个尺寸类别设置框架。
让约束为IBOutlet
属性,并在纵向或横向模式下调整它们。 您可以在Xcode的故事板中设置IBOutlet
属性。
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageHeightConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageWidthConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *buttonBottomConstraint;
// Other constraints ....
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
// Portrait mode
self.imageHeightConstraint.constant = ooo;
// Adjust other constraints
// ....
} else {
// Landscape mode
self.imageHeightConstraint.constant = xxx;
// Adjust other constraints
// ....
}
}
你不需要做任何码输出。它非常直接。你有没有对配置文件图像进行高度限制?你在使用大小班吗? – Irfan
@Ifan只给出了顶部和底部约束。如果我给左右图像消失 –
它正在消失,因为当你更新框架时,它将宽度设置为0.或者你的高度限制是错误的,并且它将它压扁以使高度为0. – noobsmcgoobs