UIRefreshControl How to detect if a user begins to

2019-09-12 01:15发布

I have a UIRefreshControl in a UITableViewController. Is there any way I can detect if a user begins to drag the View down to refresh the content? I do not mean the beginRefreshing method. I want to be able to detect when a user begins to drag down - like when the circle fills up before the beginRefreshing method is called. Is this possible?

1条回答
迷人小祖宗
2楼-- · 2019-09-12 01:34

As you have implemented UITableViewDelegate protocol you can also implement UIScrollViewDelegate which is called on scroll or drag.

Objective C

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

or

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

Swift

func scrollViewWillBeginDragging(scrollView: UIScrollView)

or

func scrollViewDidScroll(scrollView: UIScrollView)

Implement UIRefreshControl without UITableViewController Add a scrollview and put this code in your viewDidLoad

let refreshControl = UIRefreshControl()
 refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
        refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
        ScrollView.addSubview(refreshControl)
        ScrollView.contentSize = CGSizeMake(320, 800)

Add this method

func refresh (sender:AnyObject)
    {
        print("Refresh")
    }
查看更多
登录 后发表回答