2

I have a tableView inside a scrollView.

enter image description here

I want when I scroll tableView, the outer scrollView will also scroll.

Currently, when I scroll tableView, the outer scrollView not scroll.

enter image description here

So how to do this?

4
  • 1
    set tableview scrollEnabled to NO, and calculate again contain view height to fit tableview height Commented Sep 14, 2016 at 6:24
  • Thanks for your suggestion, @ABáo Commented Sep 14, 2016 at 6:38
  • How much content will you show in the scrollView, can't you simple add a headerView to the tableView? Commented Sep 14, 2016 at 7:18
  • Here is just a sample, in my real project, it content a container view which can be switched to 4 modes. Content in scrollView is depend on the tableView inside it. Commented Sep 14, 2016 at 7:20

1 Answer 1

1

//Declare the view which is going to be added as scrolling view, for instance

let requiredView = UIScrollView()

//Add your required view as subview of tableview backgroundView view like as

tableView.backgroundView = UIView() 
tableView.backgroundView?.addSubview(requiredView)

//After that control the frame of requiredHeaderView in scrollViewDidScroll delegate method like

func scrollViewDidScroll(scrollView: UIScrollView) {
         let per:CGFloat = 60 //percentage of required view to move on while moving collection view
                let deductValue = CGFloat(per / 100 * requiredView.frame.size.height)
                let offset = (-(per/100)) * (scrollView.contentOffset.y)
                let value = offset - deductValue                   
                self.requiredView.contentOffset = CGPointMake(1.0, value)
        }
Sign up to request clarification or add additional context in comments.

6 Comments

When I scroll tableView, the outer scrollView not scroll.
If your not set the contentSize for the scrollView try to set like this requiredView.contentSize = CGSizeMake(320, 500)
I've already set the contentSize for the scrollView in storyBoard.
post code about how you tried. That way I can extend my help.
where you tried my answer?, scrollViewDidScroll method contains different of my posted answer. In my answer "value" in scrollViewDidScroll method is the contentOffset.y value to move the scrollview. That way you can scroll the scroll view accordingly.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.