2016-12-01 4 views
0

가로로 스크롤하는 ScrollView 안에 ViewControllers를 넣으려고하면 각 ViewController의 너비가 무엇이든 상관없이 시도했지만 동일한 ViewController를 얻을 수 없습니다. 위의 ScrollView는 완벽하게 작동하며 UIImageView를 통해 페이징하는 데 사용됩니다. 아래 사항 중 하나가이 문제를 해결하는 더 좋은 방법입니다.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

페이지 뷰 컨트롤러를 사용할 수 있습니다. –

+0

pageviewcontroller는 전체 페이지를 가져오고 그 페이지는 UX가 아닙니다. – ahmad

+0

컨테이너보기를 사용하면 그 컨테이너에서 pageviewcontroller를 추가 할 수 있습니다. –

답변

0

당신은 행동에 Collection 뷰와 뷰 컨트롤러를 사용할 수 있습니다.

+0

컬렉션보기를 사용할 수는 있지만 이미 피할 수 있습니다. . 스크롤 문제가 전체 화면 인 경우이 문제가 발생하는 이유를 알기 어렵습니다. – ahmad

관련 문제