Scrolling Delegate in TableView

后端 未结 1 1074
猫巷女王i
猫巷女王i 2021-01-15 14:16

I want to make an animation like this link:

https://www.pinterest.com/pin/420523683937443901/sent/?sender=335307272165049646&invite_code=f63f81c77d28a48e6181db7d

相关标签:
1条回答
  • 2021-01-15 14:53

    You must use UIScrollViewDelegate in your tableView to intercept scrollView actions with:

    class YourClass: YourType, UIScrollViewDelegate {}
    

    Check the official apple documentation

    You can handle scrollview looking for scrollViewDidScroll(_:) method.

    This is just an example to add more network data when the user scroll to the end, you can use it to trigger your header animation..

    let threshold = 100.0 // threshold from bottom of tableView
    var isLoadingMore = false // flag
    
    func scrollViewDidScroll(scrollView: UIScrollView) {
        let contentOffset = scrollView.contentOffset.y
        let maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height;
    
        if !isLoadingMore && (maximumOffset - contentOffset <= threshold) {
            // Get more data - API call
            self.isLoadingMore = true
    
            // Update UI
            dispatch_async(dispatch_get_main_queue()) {
                tableView.reloadData()
                self.isLoadingMore = false
            }
        }
    }
    

    UPDATE:

    By analizying your animation, it's not simple but not impossible :) I can see two different states:

    And the second state:

    You can organize your controller by choose a UIViewController type. This UIViewController must be composed by:

    • -UINavigationController (as you can see on the top of the images , choose if you want to embedded it or link a navigation controller and set your viewController as the navigation rootViewController)
    • -UIPageView (you can use in your main viewController with the UIPageViewControllerDataSource and UIPageViewControllerDelegate, pay attention to the dimension , it cover the 30% of the top of your controller)
    • -UITableView (this is the last layout part, everytime page scroller the datasource can be changed and refreshed to the table)

    P.S. The tableViewHeader can be the gray label with the date: Thursday 21 January 2016, as you can see the dimension dont change during animation.

    0 讨论(0)
提交回复
热议问题