针对滚动视图的另一种更好的刷新控件。
在您的视图控制器类中,使用 -viewDidLoad
进行设置
- (void)viewDidLoad
{
[super viewDidLoad];
...
PRRefreshControl *refreshControl = [[PRRefreshControl alloc] init];
[refreshControl addTarget:self
action:@selector(refreshControlTriggered:)
forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
[collectionView insertSubview:refreshControl atIndex:0];
// Configure manually if needed
CGFloat customMarginTop = 10.f;
refreshControl.scrollViewContentInset = collectionView.contentInset;
refreshControl.height -= customMarginTop;
refreshControl.verticalOffset = customMarginTop * .5f;
...
}
响应动作
#pragma mark - Data
- (void)dataDidRefresh
{
[self.refreshControl endRefreshing];
}
#pragma mark - Actions
- (void)refreshControlTriggered:(PRRefreshControl *)sender
{
[self refreshData];
}
大功告成!
此代码根据 MIT 许可证 的条款和条件分发。
您可以通过以下方式支持我:
:-)