UIRefreshControl How to detect if a user begins to drag down?

梦想的初衷 提交于 2019-12-12 04:03:29

问题


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:


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")
    }


来源:https://stackoverflow.com/questions/35340237/uirefreshcontrol-how-to-detect-if-a-user-begins-to-drag-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!