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

时间:2015-11-30 10:30:20

标签: ios swift uitableview

我有一个标签,我希望仅在表格滚动时达到某个阈值时显示在tableview上。标签当前显示但不幸的是,当滚动低于阈值时不会隐藏。

这方面的一个例子是Clear App如何显示" Pull to 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

   } 

}

enter image description here

1 个答案:

答案 0 :(得分:0)

每次用户滚动时,您的代码都会创建一个新的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 } } 。所以尝试这样的事情;

$str = substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 5)), 0, $length);