ITPullToRefreshScrollView 0.0.1

ITPullToRefreshScrollView 0.0.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最近版本2014年12月

未指定 维护。



  • 作者:
  • Ilija Tovilo

ITPullToRefreshScrollViewNSScrollView的子类,允许通过下拉进行类似于iOS 7风格的刷新。ITPullToRefreshScrollView是为Play by Play应用程序创建的,由David Keegan提供资金。

感谢

使用方法

将文件包含在项目中

ITPullToRefreshScrollView有两个子模块。您需要复制以下文件:

位于/ITPullToRefreshScrollView/Classes/下的文件:

  • ITPullToRefreshScrollView.h
  • ITPullToRefreshScrollView.m
  • ITPullToRefreshClipView.h
  • ITPullToRefreshClipView.m
  • ITPullToRefreshEdgeView.h
  • ITPullToRefreshEdgeView.m
  • DuxScrollViewAnimation.h
  • DuxScrollViewAnimation.m

位于/Modules/ITProgressIndicator/ITProgressIndicator/Classes/下的文件:

  • ITProgressIndicator.h
  • ITProgressIndicator.m
  • NSBezierPath+Geometry.h
  • NSBezierPath+Geometry.m

位于/Modules/NSBKeyframeAnimation/NSBKeyframeAnimation/Classes/NSBKeyframeAnimation/下的文件:

  • NSBKeyframeAnimation.h
  • NSBKeyframeAnimation.m
  • NSBKeyframeAnimationFunctions.h
  • NSBKeyframeAnimationFunctions.c

请确保将它们复制到项目中,并将其添加到目标。

在项目中使用

请确保查看示例项目。

在Interface Builder中设置滚动视图的custom class为ITPullToRefreshScrollView。接下来您需要将一个IBOutlet连接到滚动视图。

@property (assign) IBOutlet ITPullToRefreshScrollView *scrollView;

然后您可以在代码中配置,哪个滚动视图的边缘可以进行刷新。

// Make top & bottom refreshable
self.scrollView.refreshableEdges = ITPullToRefreshEdgeTop | ITPullToRefreshEdgeBottom;

要接收来自滚动视图的通知,您需要创建一个代理。为此,您的代理类必须实现ITPullToRefreshScrollViewDelegate协议。然后您可以实现以下方法。

/**
 *  This method get's invoked when the scroll view started refreshing
 *
 *  @param scrollView - The scroll view that started refreshing
 *  @param edge       - The edge that started refreshing
 */
- (void)pullToRefreshView:(ITPullToRefreshScrollView *)scrollView
   didStartRefreshingEdge:(ITPullToRefreshEdge)edge {

  // Do stuff that takes very long

  // Don't forget to call this line!
  [scrollView stopRefreshingEdge:edge];
}

/**
 *  This method get's invoked when the scroll view stopped refreshing
 *
 *  @param scrollView - The scroll view that stopped refreshing
 *  @param edge       - The edge that stopped refreshing
 */
- (void)pullToRefreshView:(ITPullToRefreshScrollView *)scrollView
    didStopRefreshingEdge:(ITPullToRefreshEdge)edge {

  // Do UI stuff
}

最后,您必须设置滚动视图的代理以接收通知。

self.scrollView.delegate = self;

自定义

要创建自定义ITPullToRefreshEdgeView子类,覆写以下方法

// --------------------------
// ------------------- Events
// --------------------------

/**
 *  This method is called when the edge is triggered
 *
 *  @param scrollView - The sender scroll view
 */
- (void)pullToRefreshScrollViewDidTriggerRefresh:(ITPullToRefreshScrollView *)scrollView;

/**
 *  This method is called when the edge is untriggered
 *
 *  @param scrollView - The sender scroll view
 */
- (void)pullToRefreshScrollViewDidUntriggerRefresh:(ITPullToRefreshScrollView *)scrollView;

/**
 *  This method is called when the edge starts refreshing
 *
 *  @param scrollView - The sender scroll view
 */
- (void)pullToRefreshScrollViewDidStartRefreshing:(ITPullToRefreshScrollView *)scrollView;

/**
 *  This method is called when the edge stops refreshing
 *
 *  @param scrollView - The sender scroll view
 */
- (void)pullToRefreshScrollViewDidStopRefreshing:(ITPullToRefreshScrollView *)scrollView;

/**
 *  This method is called when part of the edge view becomes visible
 *
 *  @param scrollView - The sender scroll view
 *  @param progress   - The amount of the edge view that is visible (from 0.0 to 1.0)
 */
- (void)pullToRefreshScrollView:(ITPullToRefreshScrollView *)scrollView didScrollWithProgress:(CGFloat)progress;



// --------------------------
// ------------ Customisation
// --------------------------

/**
 *  Override this to remove the progress indicator and create other components
 */
- (void)installComponents;

/**
 *  The height of the edge view.
 *  Override this method to achieve a custom edge view height.
 *
 *  @return The height of the edge view
 */
- (CGFloat)edgeViewHeight;

/**
 *  Override this method to draw a custom background.
 *  You can also just override `drawRect:` and to all the drawing on your own.
 *
 *  @param The rect which should be drawn on
 */
- (void)drawBackgroundInRect:(NSRect)dirtyRect;