2015-02-09 146 views
0

我需要將我的標籤欄放在屏幕的頂部。UITabBar屏幕頂部

我試過,我做到了,這是代碼:

override func viewDidLoad() { 
     self.tabBar.frame = CGRectMake(0, 90, self.view.bounds.size.width, self.view.bounds.size.height); 
     self.tabBar.autoresizingMask = UIViewAutoresizing.FlexibleWidth 
    } 

問題是我,當我把我的設備的屏幕。

我應該重新生成這樣的佈局和變化:

self.tabBar.frame = CGRectMake(0, 80, self.view.bounds.size.width, self.view.bounds.size.height); 

我怎麼能每次都改變這一點,你打開屏幕?

編輯:

新代碼:

override func viewDidLayoutSubviews() 
    { 
     //check tabBar not null 
     if (self.tabBar != nil) 
     { 
      //make changes in frame here according to orientation if any 
      self.tabBar.frame = CGRect(x: 00, y: 20, width:self.view.bounds.size.width, height: 49) 
     } 
    } 
    override func viewDidLoad() 
    { 
    //Make changes in frame according to your requirement 
    self.tabBar.frame = CGRectMake(0, 20, self.view.bounds.size.width,49); 
    //resizing here 
    self.tabBar.autoresizingMask = UIViewAutoresizing.FlexibleTopMargin;UIViewAutoresizing.FlexibleLeftMargin;UIViewAutoresizing.FlexibleWidth;UIViewAutoresizing.FlexibleRightMargin; 
    } 

回答

2

viewDidLoad

override func viewDidLoad() 
{ 
    //Make changes in frame according to your requirement 
    self.tabBar.frame = CGRectMake(0, 20, self.view.bounds.size.width,49); 
    //resizing here 
    self.tabBar.autoresizingMask = UIViewAutoresizing.FlexibleTopMargin;UIViewAutoresizing.FlexibleLeftMargin;UIViewAutoresizing.FlexibleWidth;UIViewAutoresizing.FlexibleRightMargin; 
} 

定義UITabBar添加以下方法viewDidLayoutSubviews

override func viewDidLayoutSubviews() 
{ 
    //check tabBar not null 
    if (self.tabBar != nil) 
    { 
     //make changes in frame here according to orientation if any 
     self.tabBar.frame = CGRect(x: 00, y: 20, width:self.view.bounds.size.width, height: 49) 
    } 
} 
+0

當我嘗試寫函數返回我這個錯誤:「UITabBar不是NSString的子類型」 – Stephany 2015-02-09 14:54:04

+0

我做了一些改變,即只增加了自我tabBar。它在viewDidLayoutSubviews方法中顯示此錯誤。 – 2015-02-09 15:00:52

+0

我用新的代碼編輯了問題,但它給了我同樣的錯誤 – Stephany 2015-02-09 15:05:12