Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 1.02 KB

README.md

File metadata and controls

34 lines (24 loc) · 1.02 KB

ZNStickyRefresher

A classic refresh effect called sticky candy at QQ in iOS. (simple simulation)

You can use it by those codes:

lazy var stickyRefreshControl: ZNStickyRefreshControl = {
  let result = ZNStickyRefreshControl()
  result.addTarget(self, action: #selector(loadData), for: .valueChanged)
        
  return result
}()

tableView.stickyRefreshControl = stickyRefreshControl

@objc private func loadData() {
  // simulate network time waste
  DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) { 
    self.cellsCount += 1
            
    self.tableView.reloadData()
            
    // if refresh failed, modify result tag
    //self.stickyRefreshControl.isSuccessful = false
            
    self.stickyRefreshControl.endRefreshing()
  }
}

The next gif show the effect:

image

You can know it with this blog: http://blog.csdn.net/ZeroOnet/article/details/78160592 (Chinese, ^_^)