0

I have a ViewController which has 1000 of height and I put a few outlets to test the scrolling feature. The thing what I am trying to do is when you step into the tableView, scroll until the bottom of the tableView list and then keep scrolling to the bottom. In my code, it goes up but I can't get away from the tableView.

My storyboad with outlets: Here is my code:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let yOffset = scrollView.contentOffset.y
        let svHeight = scrollView.bounds.height
        let screenHeight = CGFloat(1000)

        if scrollView == self.scrollView {
            if yOffset >= svHeight - screenHeight {
                scrollView.isScrollEnabled = false
                myTV.isScrollEnabled = true
            }
        }

        if scrollView == self.myTV {
            if yOffset <= 0 {
                self.scrollView.isScrollEnabled = true
                self.myTV.isScrollEnabled = false
            }
        }

    }

Solution:

I found the solution in under some question and worked for my problem. Resizing the tableView for the content worked well for me.

You can find the solution here.

jorjj
  • 1,479
  • 4
  • 20
  • 36
  • Can you put some gif image descibe your problem. I don’t understand. – Thanh Vu Sep 02 '19 at 00:13
  • hi. here is the gif: https://gph.is/g/EGqezM3 as you can see, I am trying to scroll to the bottom, but I can't because my code doesn't work well. – jorjj Sep 02 '19 at 00:22
  • I see you did scroll to bottom( cell 99). I don’t understand. – Thanh Vu Sep 02 '19 at 00:26
  • The height of the entire view is 1000. I want to keep scroll the entire view after the tableView. – jorjj Sep 02 '19 at 00:27

2 Answers2

0

I think I understand what you want to do. You want to scroll to the bottom of your table view contents, and then be able to keep scrolling to display more content below in your scroll view. Is that correct?

The easiest way to do this is to delete your scroll view, and put all of your content into the table view. You will have to make some more prototype cells for your additional content, e.g. for the text view. Doing it this way means that you only have to manage the table view scrolling, which is much easier than trying to get a table view to scroll within a scrollview.

shocking
  • 848
  • 12
  • 16
  • yeah, I know to do that with MVVM. I just wanted to do some kind of challenge for myself. I really wanna solve this and work it out. – jorjj Sep 02 '19 at 00:41
  • This isn't so much a challenge as it is a poor design for your view hierarchy. Your existing layout is never going to work the way you want it to. I would recommend redesigning your view the way I suggested. – shocking Sep 02 '19 at 04:06
  • It means that unuseful doesn’t mean that we can’t try something out and learn from it. Just wanna see the result in this way. So simple. – jorjj Sep 02 '19 at 04:50
0

As your document outline section in your storyboard and the gift suggest (https://gph.is/g/EGqezM3), you're doing it wrong. Your scroll view is not working even when you swipe up on the image. In order to make your scroll view fully-working, you need to adjust a content view inside the scroll view and then put other elements like UIImageView and UITableView inside as subviews.
You may want to follow this tutorial to make it work: https://link.medium.com/riyohYxpuZ

Also, when you finish scrolling to the bottom of a table view which is inside a scroll view, your next swipe up gesture will concern the scroll view automatically. Therefore, there is no need to be worry about handling those concepts.

Soroush
  • 541
  • 4
  • 17