2
votes

I have a scrollview that contain some element (uiimage, webview ,...) in buttom of scrollview add tableview (comments list). Problem: although tableview is part of scrollview, but scrollview scroll separate and tableview scrolling separate!

enter image description here

I want at the end of scrollview and start tableview scrollview scrolling tableview and tableview scroll disabled. I used it code:

Swift:

override func intrinsicContentSize() -> CGSize {
    self.layoutIfNeeded()
    return CGSizeMake(UIViewNoIntrinsicMetric, contentSize.height)
}

Objective C:

-(CGSize)intrinsicContentSize{
[self layoutIfNeeded];
return CGSizeMake(UIViewNoIntrinsicMetric, contentSize.height)}

but don't work.

thanks for help

2

2 Answers

1
votes

That happens because it is the behavior of having a table view inside a scroll view. That should be happening.

Solution: Destroy the scrollView, and implement a tableView with a header view, wish that header view it will be the view with uiimage, webview etc... and the tableView it will be your comments. This is the best way of implementing what you want, that is if i understood right what you actually want.

Adding a header to a table view example:

self.tableView.tableHeaderView = topView // where top view is the view wish contains your uimage, buttons etc...
0
votes

Avoid bounce of ScrollView when we scroll the tableview. I have added the below line of code.It worked for me.

  self.scrollView.delegate = self
     scrollView.contentSize = CGSize(width: self.view.frame.width, height: 500)
     scrollView.showsVerticalScrollIndicator = true
     scrollView.tag = 1

   func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        if scrollView.tag != 1 {
            self.scrollView.bounces = false
        }
    }

Thanks