0

I want to put a tableView inside a pageviewcontroller which is inside a scrollview.

So I have in my storyboard :

soryboard

All constraints are respected like this

enter image description here

I disabled the tableview scroll but my scroll doesn't scroll, my tableView in TestVC1 not expand the PagerPlace in TestVC

How can I make my scrollview scroll and its content size depends on the tableview height + my red view?

EDIT

I tried your solution, then I got a storyboard like this : storyboard

Then my scrollview doesn't scroll, I don't know why,

Rodrigue
  • 102
  • 1
  • 5
  • No, I want a scrollView in TestVC, which is contains : a header (red box), something like a pageviewcontroller (with tabs (white box)) and in a children of the uipageviewcontroller, I have a tableview with custom size, So I want to scroll ALL the page and not only my tableview – Rodrigue Dec 04 '18 at 08:25
  • Here's my classic answer on UIPageViewController - maybe it will help. https://stackoverflow.com/questions/18398796/uipageviewcontroller-and-storyboard/26024779#26024779 – Fattie Dec 04 '18 at 08:31
  • No it doesn't page left and right – Rodrigue Dec 04 '18 at 08:31
  • Are you just saying there is ONE table view, which sits under the red area? is that right? – Fattie Dec 04 '18 at 08:32
  • In my case I got 2 childrens of uipageviewcontroller which each one got 1 tableview, but imagine if only 1 tab has a tableview and the other not, How can I implement it ? – Rodrigue Dec 04 '18 at 08:34
  • the answer is with container views - see answer! – Fattie Dec 04 '18 at 08:36

1 Answers1

0

In order to make your effect perfect.

Scroll View -> UIPageViewController's view -> UITableView

Scroll View has a subview of UIPageViewController's view,

UIPageViewController has many page, one page ( a controller's view ) has a subview of UITableView


Yeah. You can change the solution.

mainScrollView ( vertical slide ) -> contentScrollView ( horizontal slide ) -> contentStackView ( has many pages) -> UITableView ( one page )

mainScrollView is UIScrollView, slides in vertical,

contentScrollView is UIScrollView, slides in horizontal

contentScrollView.isPagingEnabled = true

that simulates UIPageViewController

contentStackView has many pages, one page is your UITableView


To make it work like this:

How can I make my scrollview scroll and its content size depends on the tableview height + my red view?

for the part above the UITableView

   public func scrollViewDidScroll(_ scrollView: UIScrollView) {
        
        if scrollView == mainScrollView {
            // vertical
            let offsetY = scrollView.contentOffset.y
            if offsetY >= sillValue {
                scrollView.contentOffset = CGPoint(x: 0, y: sillValue)
                currentChildScrollView?.am_isCanScroll = true
                scrollView.am_isCanScroll = false
            } else {
                let negScroll = (scrollView.am_isCanScroll == false)
                if negScroll{
                    scrollView.contentOffset = CGPoint(x: 0, y: sillValue)
                }
            }
        } 
    }

for the UITableView part

use KVO to controller the base scroll view's offset Y ,

and UITableView's offset Y is by default.

let keyValueObservation = currentChildScrollView?.observe(\.contentOffset, options: [.new, .old], changeHandler: { [weak self] (scrollView, change) in
            guard let self = self, change.newValue != change.oldValue else {
                return
            }
            self.childScrollView(didScroll: scrollView)
        })



internal func childScrollView(didScroll scrollView: UIScrollView){
        let scrollOffset = scrollView.am_originOffset.val
        
        let offsetY = scrollView.contentOffset.y
        
        if scrollView.am_isCanScroll == false {
            scrollView.contentOffset = scrollOffset
        }
        else if offsetY <= scrollOffset.y {
            scrollView.contentOffset = scrollOffset
            scrollView.am_isCanScroll = false
            mainScrollView.am_isCanScroll = true
        }
    }

the full code in github

dengST30
  • 1,898
  • 10
  • 19