Swift 在TableView中滚动委托

Swift 在TableView中滚动委托,swift,uitableview,Swift,Uitableview,我想制作一个类似以下链接的动画: 以下是我的简单屏幕截图: 在我的例子中,我希望当我向上滑动时,蓝色标题视图将消失,导航栏将变为蓝色 这是我的密码: import UIKit class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet var tableView: UITableView! @IBOutlet var headerView: U

我想制作一个类似以下链接的动画:

以下是我的简单屏幕截图:

在我的例子中,我希望当我向上滑动时,蓝色标题视图将消失,导航栏将变为蓝色

这是我的密码:

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet var tableView: UITableView!
    @IBOutlet var headerView: UIView!

    var dataSource: [String] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14].map {"\($0)"}

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.dataSource = self
        tableView.delegate = self
        headerView.backgroundColor = UIColor.blueColor()
    }

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
        cell.textLabel!.text = dataSource[indexPath.row]
        return cell
    }

}
我可以用这样的动画来改变视图,包括:导航栏、TableView的标题视图、状态栏


但是如何检查当TableView向下滚动时,标题视图将发生变化。

您必须在TableView中使用
UIScrollViewDelegate
来拦截scrollView操作:

class YourClass: YourType, UIScrollViewDelegate {}
检查

您可以处理scrollview查找方法

这只是一个示例,当用户滚动到末尾时添加更多网络数据,您可以使用它触发标题动画

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
        }
    }
}
let threshold=100.0//tableView底部的阈值
var isLoadingMore=false//标志
func scrollViewDidScroll(scrollView:UIScrollView){
设contentOffset=scrollView.contentOffset.y
设maximumOffset=scrollView.contentSize.height-scrollView.frame.size.height;

if!isLoadingMore&&(maximumOffset-contentOffset)您刚刚写了一些关于tableView的代码吗?是的,我有。我只是想问一下如何检查此事件(当tableView向下或向上滚动时)因此,在这里输入一些代码,一些图片,以清楚地了解您的问题和您的项目。不要依赖http链接,它们可能不可用,您的问题也不会有任何意义上的更改,现在是1+。但我们使用的是TableView,而不是Scroll View,是否可能?UITableView是UIScrollView的一个子类,确定这是可能的。当我添加y时我们的代码,当我向上滑动(向下滚动)时,导航栏的颜色会发生变化。谢谢。我将尝试使它更类似于该链接。它现在在(Project 53)中提供。哇,它与这里的原始照片非常相似,我看到了MovingUpHeaderView.gif,很好。