2015-11-05 69 views
1

我在故事板中有以下视图。肖像版本正常工作没有任何问题。但我想在景观视图中缩小Profile Image。然后底部项目获取屏幕上的空间。做我需要做的编码除自动版式Xcode Autolayout - 使横向视图中的子视图小

人像模式

enter image description here

风景模式

enter image description here

故事板视图

enter image description here

+0

你不需要做任何码输出。它非常直接。你有没有对配置文件图像进行高度限制?你在使用大小班吗? – Irfan

+0

@Ifan只给出了顶部和底部约束。如果我给左右图像消失 –

+0

它正在消失,因为当你更新框架时,它将宽度设置为0.或者你的高度限制是错误的,并且它将它压扁以使高度为0. – noobsmcgoobs

回答

0

您可以使用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]; 

     } 
2

你不应该觉得取向 “风景” 的了。最好将其视为垂直:紧凑型,高度:紧凑型,这对于除6+以外的所有iPhone都是基本上景观的。

在故事板的底部,你会看到一个小菜单,看起来像这样layout menu for size classes on Xcode Storyboard

选择你想要的大小类。如果你不太了解它们,Xcode会告诉你每一个代码是什么。

控制从UIImageView拖动到主要UIView并选择“等宽”并命令点击“等高”。

点击您的UIImageView。在“实用程序”检测器栏区域(右侧面板)中,单击“标尺”图标,您将看到UIImageView的约束条件。

调整“等高”和“等宽”限制为视图的百分比。您可能需要根据自己的喜好调整它。

你不需要任何超过Autolayout来做到这一点。不要直接在viewWillTransitionToSize:coordinator:中设置框架 - 通过这样做基本上可以对框架尺寸进行硬编码,并且您必须为每个尺寸类别对UITraitCollection进行大量检查,以便为每个尺寸类别设置框架。

1

让约束为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 
     // .... 
    } 
} 
5

男孩在这里是要遵循的步骤,

  • 添加高度,宽度Constrainsts到的UIImageView如下面的图

enter image description here

enter image description here

    提到
  • 您已成功添加高度,宽度约束,现在我们将在横向视图中为所有iphones添加大小类。检查照片的大小班。

enter image description here

enter image description here

enter image description here

  • 现在你与添加大小班高度约束要做,就做到了宽度的限制相同的步骤(这是你的家庭作业)。
  • 入住下面图片

enter image description here

enter image description here

+3

嘿你创建了一个项目来帮助他脱帽...... :) –