2016-07-24 26 views
1

我有一個ViewController,裏面嵌入了一個scrollView。在這個滾動視圖中,我添加了4個視圖,它們是XIB文件視圖。 XIB文件大小是「推斷」,雖然看起來是iphone5大小。加載時,它們不會自動調整大小以適應屏幕大小,它們停留在iphone5大小。將XIB文件自動調整爲屏幕大小

如何讓XIB文件的大小與其加載的屏幕大小相同?

編輯:

我自己也嘗試過這樣的代碼改變筆尖文件大小:

// 1) Create the three views used in the swipe container view 
     let AVc :AViewController = AViewController(nibName: "AViewController", bundle: nil); 
     let BVc :BViewController = BViewController(nibName: "BViewController", bundle: nil); 
     let CVc :CViewController = CViewController(nibName: "CViewController", bundle: nil); 
     let DVc :DViewController = DViewController(nibName: "DViewController", bundle: nil); 

     AVc.view.frame = CGRectMake(0 , 0, self.view.frame.width, self.view.frame.height) 
     BVc.view.frame = CGRectMake(0 , 0, self.view.frame.width, self.view.frame.height) 
     CVc.view.frame = CGRectMake(0 , 0, self.view.frame.width, self.view.frame.height) 
     DVc.view.frame = CGRectMake(0 , 0, self.view.frame.width, self.view.frame.height) 

     // 2) Add in each view to the container view hierarchy 
     // Add them in opposite order since the view hieracrhy is a stack 

     self.addChildViewController(DVc); 
     self.scrollView!.addSubview(DVc.view); 
     DVc.didMoveToParentViewController(self); 

     self.addChildViewController(CVc); 
     self.scrollView!.addSubview(CVc.view); 
     CVc.didMoveToParentViewController(self); 

     self.addChildViewController(BVc); 
     self.scrollView!.addSubview(BVc.view); 
     BVc.didMoveToParentViewController(self); 

     self.addChildViewController(AVc); 
     self.scrollView!.addSubview(AVc.view); 
     AVc.didMoveToParentViewController(self); 

這仍然沒有影響,它加載了錯誤的大小。

+0

autolayout也許? –

+0

我沒有使用任何自動佈局 –

回答

0

我建議你使用大小類,然後應用必要的常量,一開始它會有點困難,但是隨着時間的推移,你將學習如何應用大小類和常量。 Here是鏈接,你會發現最好的examples

0

如果你不使用自動佈局,那麼你可以循環只需添加四個觀點:

let bounds = UIScreen.mainScreen().bounds 
let width = bounds.size.width 
let height = bounds.size.height 

var yAxis: CGFloat = 0.0 

for i in 0...3 { 
    let rect: CGRect = CGRectMake(0, yAxis, width, height) 

    swift i { 
     case 0: 
      view1.frame = rect 
     case 1: 
      view2.frame = rect 
     case 2: 
      view3.frame = rect 
     case 3: 
      view4.frame = rect 
     default: 
      break 
    } 

    yAxis = yAxis + height 
} 

凡廠景,視圖2,VIEW3和view4是您的廈門國際銀行4點看法。 另外,將滾動視圖的內容大小設置爲高度yAxis。

建議您應該使用AutoLayout來減少代碼行。

+0

我沒有使用自動佈局,但謝謝我會給這個去。 –

+0

謝謝我已經做了一些類似的事情,但仍然沒有任何影響。我添加了我的代碼以顯示我所做的事情。 –

相關問題