UIRefreshControl - beginRefreshing not working when UITableViewController is inside UINavigationController

后端 未结 15 863
梦如初夏
梦如初夏 2020-11-28 03:03

I\'ve setup a UIRefreshControl in my UITableViewController (which is inside a UINavigationController) and it works as expected (i.e. pull down fires the correct event). Howe

15条回答
  •  广开言路
    2020-11-28 03:53

    Here is Swift 3 and later extension that shows spinner as well as animate it.

    import UIKit
    extension UIRefreshControl {
    
    func beginRefreshingWithAnimation() {
    
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
    
            if let scrollView = self.superview as? UIScrollView {
                scrollView.setContentOffset(CGPoint(x: 0, y: scrollView.contentOffset.y - self.frame.height), animated: true)
              }
            self.beginRefreshing()
          }
       }
    }
    

提交回复
热议问题