最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[基本解决]swift页面中gridView随整体页面一起滚动

iOS crifan 2468浏览 0评论

已有页面:

现在是:

下面的gridView部分的滚动,只是自己的滚动

和上面部分的内容,是脱离的,没法一起滚动

希望:下面部分是gridview的滚动,能和上面的内容,一起滚动

代码改为:

        self.view.addSubview(self.gridView)
//        constrain(gridView, statisticView) { gridView, statisticView in
//            gridView.left == gridView.superview!.left
//            gridView.right == gridView.superview!.right
//            gridView.top == statisticView.bottom + 20
//            gridView.bottom == gridView.superview!.bottom
//        }
        constrain(gridView) { gridView in
            gridView.left == gridView.superview!.left
            gridView.right == gridView.superview!.right
            //gridView.top == gridView.superview!.top
            gridView.top == gridView.superview!.top + HomeStatisticHeight
            gridView.bottom == gridView.superview!.bottom
        }
        self.gridView = GridView(columnItemSizeList: columnItemSizeList, contentList: self.contentList, gridViewFrame: CGRectMake(
            0,
            HomeStatisticHeight,
            ScreenWidth,
            ScreenHeight – (SingletonRootNC().navigationBar.frame.height + UIApplication.sharedApplication().statusBarFrame.height)))
        if self.gridViewFrame == CGRectZero {
            self.gridViewFrame = CGRectMake(
                0,
                0,
                ScreenWidth,
                ScreenHeight – (SingletonRootNC().navigationBar.frame.height + UIApplication.sharedApplication().statusBarFrame.height))
        }
        //grid view layout
        self.gridViewLayout = CustomCollectionViewLayout()
        if contentList.notEmpty {
            let firstRowTitleList = contentList[0]
            self.gridViewLayout.numberOfColumns = firstRowTitleList.count
        } else {
            self.gridViewLayout.numberOfColumns = 0
        }
        self.gridViewLayout.columnItemSizeList = columnItemSizeList
        //super.init(frame: gridViewFrame, collectionViewLayout: gridViewLayout)
        super.init(frame: self.gridViewFrame, collectionViewLayout: gridViewLayout)
        gLog.verbose("self.gridViewLayout.numberOfColumns=\(self.gridViewLayout.numberOfColumns)")
        gLog.verbose("self.gridViewFrame=\(self.gridViewFrame)")
        //gridViewFrame=(0.0, 0.0, 320.0, 504.0)

结果也还是不行。

去尝试,底层,加上一个scrollView

然后再去加上gridView

希望可以实现:

滚动grid的时候,连带整体的scrollView一起滚动。

[workaround解决]swift中scrollView中addSubview添加子视图但是显示不出来

但是结果现在还是无法满足要求:

下面的部分,被拖动的时候,还是单独拖动的

而不是带动整个部分被拖动。

算了,放弃此办法。

换去用:

一个tableview

但是没有cell

只有header和footer

分别存放对应的内容:上面是统计信息,下面是gridView

代码:

        self.tableView.backgroundColor = AppBackgoundColor
        self.view.addSubview(self.tableView)
        constrain(tableView) { tableView in
            tableView.top      == tableView.superview!.top
//            tableView.bottom   == tableView.superview!.bottom – TabBarHeight
            tableView.bottom   == tableView.superview!.bottom
            tableView.left     == tableView.superview!.left
            tableView.right    == tableView.superview!.right
        }
        //1. Today statistics views
        self.statisticView.backgroundColor = UIColor.whiteColor()
        //self.view.addSubview(self.statisticView)
//        self.scrollView.addSubview(self.statisticView)
        self.statisticView.frame = CGRectMake(0, 0, ScreenWidth, HomeStatisticHeight)
        self.tableView.tableHeaderView = self.statisticView
       self.tableView.tableFooterView = self.gridView
        self.gridView.frame = CGRectMake(0, HomeStatisticHeight, ScreenWidth, ScreenHeight – HomeStatisticHeight)
        gLog.verbose("self.gridView.frame=\(self.gridView.frame)")

结果:

效果还是不理想:

上面和下面,只有一半成都是联动的

没有完全联动起来。

然后对于gridview中去,把顶部空出来的话,但是也还是无法显示完全:

最后的最后还是用之前的tableView的header和footer

还算凑合:

但是还是不完美:

下面的gridView,的垂直方向,有时候,还是独立滚动的,不是整个页面一起滚动的。

转载请注明:在路上 » [基本解决]swift页面中gridView随整体页面一起滚动

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
85 queries in 0.212 seconds, using 22.09MB memory