【问题标题】:Add a UIPageControl to a NSCollectionLayoutSection将 UIPageControl 添加到 NSCollectionLayoutSection
【发布时间】:2021-01-29 15:24:59
【问题描述】:

所以,我正在开发一个具有如图所示结构的应用程序,其中一些部分水平滚动,正交滚动行为已发送到分页并且行为按预期工作,唯一的问题是我'我想在那里有一个 UIPageControl:

我找到了几个解释如何更新 UIPageControl 的地方,如下所示:

let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .groupPaging
section.visibleItemsInvalidationHandler = { (items: [NSCollectionLayoutVisibleItem], offset: CGPoint, environment: NSCollectionLayoutEnvironment) in
    let page = (items.last?.indexPath.row ?? 0)
    // Update page controller here
}

但是他们都没有解释如何放置 UIPageControl,没有附加的视图,没有 .xib 或任何东西,只是一些流程。

【问题讨论】:

    标签: swift uipagecontrol uicollectionviewcompositionallayout


    【解决方案1】:

    一种方法是将页面控件(或包含页面控件的视图)注册为“补充视图”,然后将其作为boundarySupplementaryItems 的一部分添加到NSCollectionLayoutSection。当您将补充视图出列时,您会在某处存储对它的引用,然后您可以将其作为 section.visibleItemsInvalidationHandler 实现的一部分进行访问。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 2022-06-16
      • 1970-01-01
      相关资源
      最近更新 更多