LoadingPlaceholderView
零努力即可使用的动画渐变占位符
混合 UI 组件 | 表格视图 | 集合视图 |
---|---|---|
![]() |
![]() |
![]() |
特征
- 即插即用
- 支持所有 UIKit 组件,并且对用户自定义组件开放。
- 支持横屏模式和运行时屏幕调整大小
- 高度可定制
- Swift 4 和 iOS 9.0+
如何工作
LoadingPlaceholderView
从 viewToCover
中提取遵守协议 Coverable
的所有子视图,然后创建一个动画渐变层,组合每个子视图提供的所有 coverablePath
。
设置
将 pod 'LoadingPlaceholderView'
添加到您的 Podfile,或将 LoadingPlaceholderView
文件夹的内容复制到您的项目中。
如何使用
-
创建
LoadingPlaceholderView
实例let loadingPlaceholderView = LoadingPlaceholderView()
通常情况下,这将是视图控制器的一个属性。
-
显示视图
loadingPlaceholderView.cover(_ viewToCover: UIView, animated: Bool)
-
隐藏视图
loadingPlaceholderView.uncover(animated: Bool)
UITableView/UICollectionView
设计上,《LoadingPlaceholderView》不会通过注入模拟数据干预DataSource
和/或Delegate
,而是将决定显示什么和如何显示的责任留给用户;这样就可以最大限度地减少不必要的副作用。
-
预加载tableView/collectionView的“模拟”单元格。
UITableViewCell
和UICollectionViewCell
已符合Coverable
-
显示视图
loadingPlaceholderView.cover(_ viewToCover: UIView, animated: Bool)
-
隐藏视图并刷新tableView/collectionView
loadingPlaceholderView.uncover(animated: Bool)
tableView/collectionView.reloadData()
注意
您可以为coverableCellsIdentifiers
(仅适用于UITableView
)设置值 - 这样就可以忽略当前tableView的状态,并使用提供的单元格标识来生成coverablePath
(因此是渐变)。这样就可以跳过之前列表中的第一步,因为不再需要用模拟单元格填充tableView。
自定义
您可以通过设置以下属性来自定义组件行为
fadeAnimationDuration: TimeInterval
由方法执行的动画的duration
cover(_ viewToCover: UIView, animated: Bool = true)
uncover(animated: Bool = true)
当animated为true
gradientColor: UIColor
渐变的主要颜色。一旦设置,将基于此颜色计算
gradientConfiguration.backgroundColor
、gradientConfiguration.primaryColor
和gradientConfiguration.secondaryColor
。
gradientiConfiguration.width: Double
渐变大小中主要颜色的宽度,以百分比表示。
gradientiConfiguration.animationDuration: TimeInterval
渐变动画的duration
gradientiConfiguration.backgroundColor: UIColor
渐变的 backgroundColor
gradientiConfiguration.primaryColor: UIColor
渐变的 primaryColor
gradientiConfiguration.secondaryColor: UIColor
渐变的 secondaryColor
演示
在这个仓库中,您还可以找到一个演示。
信息
如果您喜欢这个git,您可以在这里或Twitter上关注我 :) @MarioIannotta
意大利向您问好!