2015-05-25 106 views
3

我已經閱讀自動佈局多以前的職位,並在iOS的7狀態欄的行爲,仍然不知道如何讓我的Autolay-ED出物體爲狀態欄下方的下方。獲取自動佈局狀態欄

我現在有

self.automaticallyAdjustsScrollViewInsets = YES; 
self.edgesForExtendedLayout = UIRectEdgeNone; 

和搜索欄已應用像V:|-0-searchBar-|視覺格式。

按照預期,搜索欄呈現在狀態欄下,如 enter image description here

我一直無法找到一個解決方案,以獲得搜索欄,在狀態欄的底部邊緣開始。如何才能做到這一點?

編輯:我已經看過頂部佈局選項,但我有我的自定義視圖控制器的xib。沒有頂層佈局指南可用。我怎樣才能支持這個設置?我想避免檢查系統版本。 ib screenshot

回答

0

我可以按照此answer以編程方式訪問頂部引導。我是用XIBs我的自定義類,因此無法通過圖形界面生成器訪問topLayoutGuide,如下圖所示。

ib screenshot 相反topLayoutGuide可以通過[self topLayoutGuide],其中自是UIViewController進行訪問。 Documentation link

if ([self respondsToSelector:@selector(topLayoutGuide)]) { 
    id topGuide = [self topLayoutGuide]; 
    NSDictionaryOfVariableBindings(topGuide ...