一个受 Storehouse iOS 应用启发的 全自定义 下拉刷新控件,用于 iOS
您可以通过一个 plst 文件使用任何形状,比如这个就是我的 公司 的标志
您只需在您的项目中包含 CBStoreHouseRefreshControl (.h .m)
和 BarItem (.h .m)
。
CocoaPods 支持很快就来了!
您可以使用如下简单的静态方法将其附加到任何 UIScrollView
,例如 UITableView
或 UICollectionView
+ (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView
target:(id)target
refreshAction:(SEL)refreshAction
plist:(NSString *)plist;
self.storeHouseRefreshControl = [CBStoreHouseRefreshControl attachToScrollView:self.tableView target:self refreshAction:@selector(refreshTriggered:) plist:@"storehouse"];
或者,使用这个方法以获得更多可配置选项
+ (CBStoreHouseRefreshControl*)attachToScrollView:(UIScrollView *)scrollView
target:(id)target
refreshAction:(SEL)refreshAction
plist:(NSString *)plist
color:(UIColor *)color
lineWidth:(CGFloat)lineWidth
dropHeight:(CGFloat)dropHeight
scale:(CGFloat)scale
horizontalRandomness:(CGFloat)horizontalRandomness
reverseLoadingAnimation:(BOOL)reverseLoadingAnimation
internalAnimationFactor:(CGFloat)internalAnimationFactor;
self.storeHouseRefreshControl = [CBStoreHouseRefreshControl attachToScrollView:self.tableView target:self refreshAction:@selector(refreshTriggered:) plist:@"storehouse" color:[UIColor whiteColor] lineWidth:1.5 dropHeight:80 scale:1 horizontalRandomness:150 reverseLoadingAnimation:YES internalAnimationFactor:0.5];
然后,在您的 UIViewController
中实现 UIScrollViewDelegate
,如果您还没有的话,并将调用传递给刷新控件
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self.storeHouseRefreshControl scrollViewDidScroll];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
[self.storeHouseRefreshControl scrollViewDidEndDragging];
}
最后,确保您已实现了之前传入的 refreshAction
以监听刷新触发器
- (void)refreshTriggered
{
//call your loading method here
//Finshed loading the data, reset the refresh control
[self.storeHouseRefreshControl finishedLoading];
}
有关更多详细信息,请查看示例应用的代码。
CBStoreHouseRefreshControl 的形状包含许多用于动画的 BarItem
,每个 BarItem
都运行自己的动画。您需要通过 plist 文件提供 startPoint
和 endPoint
。
所有 BarItem
将共享统一的坐标系,其原点在左上角。例如,如果您想画一个方框,plist 将如下所示
结果将如下所示
注意
startPoints
和 endPoints
。{x,y}
) 对坐标进行排序。reverseLoadingAnimation
可以反转动画。startPoint
和 endPoint
会更容易,更多信息请查看 这里。通过以下参数与 CBStoreHouseRefreshControl 的视图和动画进行交互
color
参数设置条颜色lineWidth
参数设置条宽度dropHeight
参数设置控件的的高度scale
参数设置控件的比例horizontalRandomness
参数来调整条目项出现的分散程度reverseLoadingAnimation
参数设置是否反转加载动画,如果设置为 YES
,则最后条目项会首先突出显示。internalAnimationFactor
参数调整出现/消失动画的时间偏移量,例如如果 internalAnimationFactor
为 1,则所有条目项将同时出现/消失。Suyu Zhang
[email protected]
suyuzhang.com
版权(c)2014 Suyu Zhang [email protected]. 请查阅 LICENSE 文件了解许可权和使用限制(MIT)。