2016-11-19 209 views
-1

我已將視圖控制器的視圖放置在滾動視圖中。但是當我在iPhone 6Plus上運行我的應用程序時,我的視圖沒有填滿屏幕,我可以看到右側的其他視圖。我該如何解決這個問題。調整滾動視圖內的視圖

這裏的問題是

image

截圖,這是我的代碼

contentView.contentSize = CGSize(width: contentView.frame.size.width * 5, height: contentView.frame.size.height) 


     rifleViewController.view.frame = contentView.bounds 
     contentView.addSubview(rifleViewController.view) 

     pistolViewController.view.frame = contentView.bounds 
     pistolViewController.view.frame.origin.x = contentView.frame.size.width 
     contentView.addSubview(pistolViewController.view) 

     shotgunViewController.view.frame = contentView.bounds 
     shotgunViewController.view.frame.origin.x = contentView.frame.size.width * 2 
     contentView.addSubview(shotgunViewController.view) 

     smgsViewController.view.frame = contentView.bounds 
     smgsViewController.view.frame.origin.x = contentView.frame.size.width * 3 
     contentView.addSubview(smgsViewController.view) 

     sniperViewController.view.frame = contentView.bounds 
     sniperViewController.view.frame.origin.x = contentView.frame.size.width * 4 
     contentView.addSubview(sniperViewController.view) 
+0

爲什麼不使用'UICollectionView'?將UIViewControllers添加爲子視圖控制器?它提供了完全相同的功能。 – Rikh

+0

你在哪裏設置'scrollView'的contentSize? – Adeel

回答

0

我已經解決了我的問題。事實證明,我忘了添加自動調整大小到我的滾動視圖。 (愚蠢的錯誤)感謝大家的答案!