2014-09-04 94 views
0

所以我一直在移動代碼的一部分使用約束,而不是使用框架的舊方法。這是我需要移動的當前代碼。當用戶按下按鈕時隱藏\取消隱藏下方的tabbar,我需要更改視圖的高度。如何使用約束設置自身視圖高度?

CGRect newFrame = self.view.frame; 
newFrame.size.height += 44 
self.view.frame = newFrame; 

self.view是UIViewController。我想設置圖片中顯示的視圖的高度。沒有辦法給它添加一個高度約束(你可以很容易地將它設置在子視圖上,我不想要)Selected View whose height needs to be set using constraints

我沒有看到使用約束設置自身視圖高度的方法。

感謝 arpit

回答

1

這短短的tutorial將是對你有幫助。

可以使用VFL做到這一點(我個人比較喜歡,見上面的鏈接),或者通過這種代碼:

[yourView addConstraint:[NSLayoutConstraint constraintWithItem:yourView  
                attribute:NSLayoutAttributeHeight 
                relatedBy:0 
                 toItem:nil 
                attribute:NSLayoutAttributeNotAnAttribute 
                multiplier:1 
                 constant:requiredHeight]]; 

這段代碼將在高度添加約束由requiredHeight指定yourView。在開始編碼之前,請查看intrinsicContentSize和updateConstraints方法。

設置約束時,請記得首先設置(對於視圖您將設置約束)translatesAutoresizingMaskIntoConstraints標誌爲NO(默認設置爲YES)。同時閱讀this應該對這個話題有所瞭解。

相關問題