简体   繁体   中英

Swift: How can I stop scrolling while scrolling in a tableView and then keep scrolling after the last tableView item?

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 .

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, eg 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM