Ios 当滚动TableView达到阈值时在TableView上显示文本

Ios 当滚动TableView达到阈值时在TableView上显示文本,ios,swift,uitableview,Ios,Swift,Uitableview,我有一个标签,只有在滚动时表格达到某个阈值时,我才想在表格视图上显示。标签当前显示,但不幸的是,当滚动低于阈值时,标签没有隐藏 例如,Clear应用程序如何显示如图所示的“拉动清除”标签 下面是我的代码尝试。也许我没有适当地隐藏标签。不确定。谢谢你的帮助 func scrollViewDidScroll(scrollView: UIScrollView) { let swipeFurther = UILabel() swipeFurther.frame = C

我有一个标签,只有在滚动时表格达到某个阈值时,我才想在表格视图上显示。标签当前显示,但不幸的是,当滚动低于阈值时,标签没有隐藏

例如,Clear应用程序如何显示如图所示的“拉动清除”标签

下面是我的代码尝试。也许我没有适当地隐藏标签。不确定。谢谢你的帮助

func scrollViewDidScroll(scrollView: UIScrollView) {


        let swipeFurther = UILabel()
        swipeFurther.frame = CGRectMake(10.0, 33.0, 300.0, 20.0)
        swipeFurther.text = "Swipe Further to open the settings."
        swipeFurther.textAlignment = .Left
        swipeFurther.textColor = UIColor.whiteColor()
        swipeFurther.font = UIFont(name: "SF UI Text Regular", size: 9)
        self.view.insertSubview(swipeFurther, aboveSubview: self.tableView)

       swipeFurther.hidden = true    

   if (tableView.contentOffset.y < -(80.0)) {

           swipeFurther.hidden = false

   } 

}
func scrollViewDidScroll(scrollView:UIScrollView){
设swipeFurther=UILabel()
swipeFurther.frame=CGRectMake(10.0,33.0,300.0,20.0)
swipeFurther.text=“进一步滑动以打开设置。”
swipeFurther.textAlignment=.Left
swipeFurther.textColor=UIColor.whiteColor()
swipeFurther.font=UIFont(名称:“SF UI文本常规”,大小:9)
self.view.insertSubview(swipeFurther,在子视图上方:self.tableView)
swipeFurther.hidden=true
如果(tableView.contentOffset.y<-(80.0)){
swipeFurther.hidden=false
} 
}

每次用户滚动时,您的代码都会创建一个新的
UILabel
,如果满足条件,则只隐藏最新的标签。所以试试这样的东西

let swipeFurther = UILabel()

override func viewDidLoad() {
    super.viewDidLoad()

    swipeFurther.frame = CGRectMake(10.0, 33.0, 300.0, 20.0)
    swipeFurther.text = "Swipe Further to open the settings."
    swipeFurther.textAlignment = .Left
    swipeFurther.textColor = UIColor.whiteColor()
    swipeFurther.font = UIFont(name: "SF UI Text Regular", size: 9)
    self.view.insertSubview(swipeFurther, aboveSubview: self.tableView)
}

func scrollViewDidScroll(scrollView: UIScrollView) {
    if (tableView.contentOffset.y < -(80.0)) {
        swipeFurther.hidden = false
    } else {
        swipeFurther.hidden = true
    }
}
let swipeFurther=UILabel()
重写func viewDidLoad(){
super.viewDidLoad()
swipeFurther.frame=CGRectMake(10.0,33.0,300.0,20.0)
swipeFurther.text=“进一步滑动以打开设置。”
swipeFurther.textAlignment=.Left
swipeFurther.textColor=UIColor.whiteColor()
swipeFurther.font=UIFont(名称:“SF UI文本常规”,大小:9)
self.view.insertSubview(swipeFurther,在子视图上方:self.tableView)
}
func scrollViewDidScroll(scrollView:UIScrollView){
如果(tableView.contentOffset.y<-(80.0)){
swipeFurther.hidden=false
}否则{
swipeFurther.hidden=true
}
}

非常感谢。工作完美。:)