一个用于管理标题视图的折叠和展开的UIView子类。标题的子视图被配置为转换为任何折叠布局。标题设计用于与UIScrollView或UITableView一起工作,当用户滚动内容时,但无论如何都可以以其他方式使用。
pod 'MGCollapsibleHeader'
或者简单地将MGCollapsibleHeader/
文件夹复制到您的项目中。
要使用可折叠标题,您必须首先使用标题视图配置您的UIViewController
。只需将此视图的类设置为MGCollapsibleHeaderView
,然后它就准备好配置了。视图默认折叠到60 px大小,但可以设置
[self.headerView setMinimumHeaderHeight:100.]
然后您可以提供body视图的上部NSLayoutConstraint
以在标题折叠时展开。
[self.headerView setBodyViewTop:self.tableViewTop]
接下来,将任何标题的子视图(或任何视图)添加到与标题一起折叠的动画中。有两个方法可供您选择
addTransformingSubview:attributes:
添加一个用户滚动时转换的视图。必须提供一个MGTransformAttribute
数组来描述转换。有关更多信息,请参见属性。addFadingSubview:fadeBy:
添加一个用户滚动时淡入淡出的视图。 [self.headerView addFadingSubview:self.button1 fadeBy:.4];
[self.headerView addFadingSubview:self.label fadeBy:.75];
[self.headerView addTransformingSubview:self.button4
attributes:@[[MGTransformAttribute attribute:MGAttributeX value:520.],
[MGTransformAttribute attribute:MGAttributeY value:20.],
[MGTransformAttribute attribute:MGAttributeWidth value:40.],
[MGTransformAttribute attribute:MGAttributeHeight value:35.]]];
[self.headerView addTransformingSubview:self.titleLabel
attributes:@[[MGTransformAttribute attribute:MGAttributeY value:20.],
[MGTransformAttribute attribute:MGAttributeWidth value:120.],
[MGTransformAttribute attribute:MGAttributeHeight value:34.],
[MGTransformAttribute attribute:MGAttributeCornerRadius value:17.]]];
最后,触发标题视图的折叠。如果使用滚动,则在scrollViewDidScroll
代理调用中执行此操作是理想的。
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.headerView collapseToOffset:scrollView.contentOffset];
}
属性用于描述折叠结束时子视图。以下是目前可用的
MGAttributeX
MGAttributeY
MGAttributeWidth
MGAttributeHeight
MGAttributeAlpha
MGAttributeCornerRadius
MGAttributeShadowRadius
MGAttributeShadowOpacity
这些属性将(线性)从对应视图的默认值动画到这些属性。