2016-07-24 16 views
1

私は内部にscrollViewが組み込まれたView Controllerを持っています。このスクロールビューでは、XIBファイルビューである4つのビューが追加されています。 XIBファイルのサイズは、iphone5サイジングのように見えますが、「推測」です。ロードされると、画面のサイズに自動リサイズされず、iphone5サイズに留まります。XIBファイルのサイズを画面サイズに合わせて自動調整する

XIBファイルを読み込んでいる画面と同じサイズにするにはどうすればよいですか?

EDIT:

私はまた、このようなコードをnibファイルのサイズを変更しようとしている:

// 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

あなたは、あなたが単にforループによって4つのビューを追加することができ、自動レイアウトを使用していない場合:

VIEW1、VIEW2、view3とview4があなたの4つのXIB図である
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 
} 

。 また、スクロールビューのコンテンツサイズを高さyAxisに設定します。

推奨されていますが、AutoLayoutを使用するとコード行が減少します。

+0

私は自動レイアウトを使用していませんが、ありがとうございます。 –

+0

ありがとう、私はすでにこれに類似したことをしていますが、まだ影響はありません。私が行ったことを示すためにコードを追加しました。 –

関連する問題