2016-12-01 12 views
0

ViewControllerを水平スクロールのScrollViewに配置しようとしていて、各ViewControllerの幅が何であっても試してみましたが、それぞれのViewControllerを同じにすることはできません。上記のScrollViewは完全にうまく動作し、UIImageViewのページングに使用されます。下の1つが問題ですが、おそらくこれを達成するためのより良い方法があります。iOS 10 Swift 3 - ViewController inside ScrollView

これに助けていただければ幸いです。他の人のためにコードを貼り付けます。それが役に立てば幸い。

enter image description here

contentScrollView.translatesAutoresizingMaskIntoConstraints = false 

    // Create the three views used in the swipe container view 
    let storyboard = UIStoryboard(name: "Main", bundle: nil) 

    let aboutVC: AboutViewController = storyboard.instantiateViewController(withIdentifier: "AboutViewController") as! AboutViewController 
    let categoriesVC: CategoriesViewController = storyboard.instantiateViewController(withIdentifier: "CategoriesViewController") as! CategoriesViewController 
    let reviewsVC: ReviewsViewController = storyboard.instantiateViewController(withIdentifier: "ReviewsViewController") as! ReviewsViewController 

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

    self.addChildViewController(aboutVC) 
    self.contentScrollView!.addSubview(aboutVC.view) 
    aboutVC.didMove(toParentViewController: self) 

    self.addChildViewController(categoriesVC) 
    self.contentScrollView!.addSubview(categoriesVC.view) 
    categoriesVC.didMove(toParentViewController: self) 

    self.addChildViewController(reviewsVC) 
    self.contentScrollView!.addSubview(reviewsVC.view) 
    reviewsVC.didMove(toParentViewController: self) 


    contentScrollView.bringSubview(toFront: contentScrollView) 
    // Set up the frames of the view controllers to align 
    // with eachother inside the container view 
    print("scroll view frame bounds: \(self.pagerScrollView.frame.width)") 
    print("view frame bounds: \(self.view.frame.width)") 
    print("screen main bounds: \(UIScreen.main.bounds.size.width)") 


    let width = self.view.frame.width 

    aboutVC.view.frame = CGRect(x: 0, y: 0, width: width, height: contentScrollView.frame.size.height) 
    categoriesVC.view.frame = CGRect(x: width, y: 0, width: width, height: contentScrollView.frame.size.height) 
    reviewsVC.view.frame = CGRect(x: 2 * width, y: 0, width: width, height: contentScrollView.frame.size.height) 

    // Finally set the size of the scroll view that contains the frames 
    self.contentScrollView!.contentSize = CGSize(width: 3 * self.pagerScrollView.frame.width, height: contentScrollView.frame.size.height) 
+0

あなたはpageviewcontrollerを使用できます。 –

+0

pageviewcontrollerはページ全体を取ります。それは私が行っているUXではありません – ahmad

+0

コンテナビューを使用するとそのコンテナでページビューコントロールを追加できます –

答えて

0

あなたは行為にCollectionビューとビューコントローラを使用することができます。

+0

私はコレクションビューを使用できますが、既にそこには1つありますので、 。私は、なぜこの問題が起こっているのかに悩まされており、スクロールビューがフルスクリーンであれば完全に機能しています。 – ahmad