CBStoreHouseRefreshControl 1.0

CBStoreHouseRefreshControl 1.0

测试测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2014年12月

Suyu Zhang 维护。




这是什么?

一个受 Storehouse iOS 应用启发的 全自定义 下拉刷新控件,用于 iOS

screenshot1

您可以通过一个 plst 文件使用任何形状,比如这个就是我的 公司 的标志

screenshot2

需要哪些文件?

您只需在您的项目中包含 CBStoreHouseRefreshControl (.h .m)BarItem (.h .m)

CocoaPods 支持很快就来了!

如何使用它

您可以使用如下简单的静态方法将其附加到任何 UIScrollView,例如 UITableViewUICollectionView

+ (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 文件提供 startPointendPoint

所有 BarItem 将共享统一的坐标系,其原点在左上角。例如,如果您想画一个方框,plist 将如下所示

screenshot2

结果将如下所示

screenshot3

注意

  • 请确保使用正确的键,即 startPointsendPoints
  • 请确保使用正确的格式 ({x,y}) 对坐标进行排序。
  • 高亮/加载动画将以您在 plist 中声明的顺序突出显示每个条目,使用 reverseLoadingAnimation 可以反转动画。
  • @isaced 提到使用 PaintCode 生成 startPointendPoint 会更容易,更多信息请查看 这里

配置

通过以下参数与 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)。