2016-07-24 27 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

谢谢我已经做了一些类似的事情,但仍然没有任何影响。我添加了我的代码以显示我所做的事情。 –

相关问题