【问题标题】:how to make search bar to move up and hide while scroll in table view?如何在表格视图中滚动时使搜索栏向上移动和隐藏?
【发布时间】:2018-05-28 03:14:37
【问题描述】:

我曾尝试在滚动表格视图图像时显示和隐藏,但在这里我需要像当我开始滚动表格视图时搜索栏也需要转到顶部并隐藏,当我向下滚动搜索栏时需要随着表格视图滚动下来并固定在同一位置,谁能帮我实现这个?

这是我已经尝试在表格视图滚动时检测滚动的代码

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {

        if(velocity.y>0) {
            //Code will work without the animation block.I am using animation block incase if you want to set any delay to it.
            UIView.animate(withDuration: 1.5, delay: 0, options: UIViewAnimationOptions(), animations: {
                self.searchBar.isHidden = true
                print("Hide")
            }, completion: nil)

        } else {
            UIView.animate(withDuration: 1.5, delay: 0, options: UIViewAnimationOptions(), animations: {
                self.searchBar.isHidden = false
                print("Unhide")
            }, completion: nil)    
        }
    }

【问题讨论】:

    标签: ios swift3 uiscrollview


    【解决方案1】:

    简单的将搜索栏拖到tableview中。

    【讨论】:

    • 不,我需要在此处显示的表格视图图像顶部有搜索栏
    • 将搜索栏拖到 tablview 单元格。它将加入 tablview 单元格的顶部。
    • 是的,搜索栏使用 tableview 滚动。
    • 但是如果我放在单元格上,我有很多图像,那么它会根据你的想法显示在所有单元格上,不是吗?
    猜你喜欢
    • 2018-05-16
    • 2014-08-23
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多