问题
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