如何使contview滚动滚动卷轴自然行为

发布于 2025-01-27 07:22:06 字数 605 浏览 3 评论 0原文

我需要做这个应用程序。 当滚动主视图时,视图层次结构会像这样

UIScrollView
-UIView (Main View)
--UIView (Top View Container)
--UITableview

,如果表观视图具有许多单元格,则表视图应升至顶部,一旦它到达顶部。用户应该能够滚动表视图单元格。我能够实现它,但它并不能自然滚动。

附加了我的代码 https://githbithub.com/github.com/iamshimshimak/iamshimak/finchhomescreenredesign.git

I need to do this app. The view hierarchy goes like this

UIScrollView
-UIView (Main View)
--UIView (Top View Container)
--UITableview

When scrolling up the Main View, If table view has many cells, the table view should go to the top, and once it reaches the top. The user should be able to scroll the table view cells. I was able to achieve it but it doesn't scroll naturally.

Screen Idea

Attached my code https://github.com/iamshimak/FinchHomeScreenRedesign.git

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吹梦到西洲 2025-02-03 07:22:06

首先,切勿将tableview放入卷轴上,这是一个不好的做法。您可以只使用tableView标头,然后在表观视频单元格之前嵌入任何类型的视图。

这是我如何处理它的狙击:

//MARK: ConfigureTableView
    private func configureTableView(){
        let footerView = UIView()
        footerView.frame.size.height = 50
        footerView.backgroundColor = .white
        self.tableView.tableFooterView = footerView
        self.tableView.tableHeaderView = self.headerView
        var newFrame = headerView.frame

        newFrame.size.width = view.bounds.width
        newFrame.size.height = 300
        headerView.frame = newFrame
        
        tableView.backgroundView = UIView()
        tableView.backgroundView?.addSubview(backgroundTableView)
    }

如您所见,我将Uiview嵌入为页脚,而另一个名为Headerview作为标头的Uiview,

但是如果您坚持要在scrollview中使用tableview,则可以尝试使用scrollview disemview和测定哪个滚动浏览正在滚动


func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let yOffset = scrollView.contentOffset.y
    
    if scrollView == self.scrollView {
        if yOffset >= scrollViewContentHeight - screenHeight {
           // logic when using scrollview
        }
    }
    
    if scrollView == self.tableView {
        if yOffset <= 0 {
            // logic when using tableview scrollView
        }
    }

}

First, never put tableview inside a scrollview, it's a bad practice. You could just use tableview header and embed any type of view do you want before the tableview cells.

here's a snipeste on how I deal with it:

//MARK: ConfigureTableView
    private func configureTableView(){
        let footerView = UIView()
        footerView.frame.size.height = 50
        footerView.backgroundColor = .white
        self.tableView.tableFooterView = footerView
        self.tableView.tableHeaderView = self.headerView
        var newFrame = headerView.frame

        newFrame.size.width = view.bounds.width
        newFrame.size.height = 300
        headerView.frame = newFrame
        
        tableView.backgroundView = UIView()
        tableView.backgroundView?.addSubview(backgroundTableView)
    }

as you can see, I embedded a UIView as a footer and another UIView named headerView as a header

but if you insist of using a tableview inside a scrollview, you can try using a scrollview delegate and detech which scrollview is scrolling


func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let yOffset = scrollView.contentOffset.y
    
    if scrollView == self.scrollView {
        if yOffset >= scrollViewContentHeight - screenHeight {
           // logic when using scrollview
        }
    }
    
    if scrollView == self.tableView {
        if yOffset <= 0 {
            // logic when using tableview scrollView
        }
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文