BONavigationPullToRefresh 0.9

BONavigationPullToRefresh 0.9

测试已测试
语言语言 SwiftSwift
许可 MIT
发布上次发布Sep 2016
SPM支持 SPM

Bruno Oliveira 维护。



BONavigationPullToRefresh

示例

要运行示例项目,克隆仓库,并首先从 Example 目录中运行 pod install

演示项目需要 iOS9

要求

安装

BONavigationPullToRefresh 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile

pod "BONavigationPullToRefresh"

要开始使用,只需配置当前 ViewController 导入

import BONavigationPullToRefresh

简单用例

class ExampleViewController: UIViewController, NavigationPullRefreshable {
  let fakeLoadingTime = dispatch_time(DISPATCH_TIME_NOW, Int64(4 * NSEC_PER_SEC))
  @IBOutlet weak var scrollView: UIScrollView!

  override func viewDidLoad() {
    super.viewDidLoad()

    // Maximum height for the loading view
    let maxHeight: CGFloat = self.navigationController?.navigationBar.absoluteHeight ?? 10

    // Configurations to animate the default RefreshableView
    let configurations = DefaultRefreshingViewConfigurations(maxHeight: maxHeight,
                                                             image: UIImage(named: "sample"))

    let refreshableView = DefaultRefreshingView(configurations: configurations)


    addNavigationPullToRefresh(toScrollView: self.scrollView, refreshingView: refreshableView) {
      let fakeLoadingTime = dispatch_time(DISPATCH_TIME_NOW, Int64(10 * NSEC_PER_SEC))
      dispatch_after(fakeLoadingTime, dispatch_get_main_queue()) {
        self.endRefreshing()
      }
    }
  }
}

刷新视图

刷新视图是一个符合 RefreshableView 协议的 UIView

public protocol RefreshableView {
  // View will start refreshing
  func startRefreshing()

  // Loading has beed canceled due to ViewController disapear
  func cancelRefreshing()

  // Loading has finished successfully
  func endRefreshing()

  // View needs to be updated to the percentage of loading given (bettween 0 - 1)
  func updateLoadingItem(percentage: CGFloat)
}

您可以使用 DefaultRefreshingView,它在示例中只更新其 alpha。

默认刷新视图

  // configurations is a DefaultRefreshingViewConfigurations
  DefaultRefreshingView(configurations: configurations)

默认刷新视图配置

public struct DefaultRefreshingViewConfigurations {

// Maximum view Size
var maxHeight: CGFloat = 80

  // View inset
  var inset = CGPoint.zero

  // Image to be shown
  var image: UIImage?

  // Scaling option of the UIImageView
  var imageOptions = UIViewContentMode.ScaleToFill

  // Animation time
  var animationTime: NSTimeInterval = 1

  // Fade animation Time
  var animationFadeTime: NSTimeInterval = 0.5
}

结束刷新

self.endRefreshing()

生命周期

为了保持 viewControllers 栈生命周期,需要在您的 ViewController 上调用三个更多的方法

override func viewWillAppear(animated: Bool) {
  super.viewWillAppear(animated)
  viewControllerWillShow()
}

override func viewDidAppear(animated: Bool) {
  super.viewDidAppear(animated)
  viewControllerDidShow()
}

override func viewWillDisappear(animated: Bool) {
  super.viewWillDisappear(animated)
  viewControllerWillDisappear()
}

NavigationPullRefreshable 支持的所有方法如下

public protocol NavigationPullRefreshable {
  // Configure the NavigationPullToRefresh
  func addNavigationPullToRefresh(toScrollView scrollView: UIScrollView,
                                               refreshingView: RefreshableView,
                                               startLoading: () -> Void)

  // You must call when the ViewController appears to pause loader when viewController is pushed
  func viewControllerWillShow()

  // You must call when the ViewController didAppear to set the refreshable view below the title
  func viewControllerDidShow()

  // You must call when the ViewController will disappear to pause loader when viewController is popped
  // or pushed
  func viewControllerWillDisappear()

  func endRefreshing()
}

配置

  // Distance needed to trigger refresh
  public var triggerDistance: CGFloat = 80

作者

Bruno Oliveira,[email protected]

许可

BONavigationPullToRefresh 受 MIT 许可协议保护。有关更多信息,请参阅 LICENSE 文件。