2015-11-05 62 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

嘿你創建了一個項目來幫助他脫帽...... :) –