仿咸鱼上拉刷新
#pragma mark - 重写方法
#pragma mark 在这里做一些初始化配置(比如添加子控件)
- (void)prepare
{
[super prepare];
// 设置控件的高度
self.mj_h = 50;
}
#pragma mark 在这里设置子控件的位置和尺寸
- (void)placeSubviews
{
[super placeSubviews];
}
#pragma mark 监听scrollView的contentOffset改变
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
{
[super scrollViewContentOffsetDidChange:change];
}
#pragma mark 监听scrollView的contentSize改变
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
{
[super scrollViewContentSizeDidChange:change];
}
#pragma mark 监听scrollView的拖拽状态改变
- (void)scrollViewPanStateDidChange:(NSDictionary *)change
{
[super scrollViewPanStateDidChange:change];
}
#pragma mark 监听控件的刷新状态
- (void)setState:(MJRefreshState)state
{
MJRefreshCheckState;
switch (state) {
case MJRefreshStateIdle:
[self dismissActivity];
break;
case MJRefreshStatePulling:
break;
case MJRefreshStateRefreshing:
[self showActivityView];
break;
default:
break;
}
}
- (void)showActivityView {
if (!_activityImageView) {
UIImageView *activity = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 52, 16)];
_activityImageView = activity;
activity.center = CGPointMake(self.mj_w * 0.5, self.mj_h * 0.5);
[self addSubview:activity];
}
NSMutableArray *refreshingImages = [NSMutableArray array];
for (NSUInteger i = 1; i<=29; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"loading_v1_%05lu", (unsigned long)i]];
[refreshingImages addObject:image];
}
_activityImageView.animationImages = refreshingImages;
_activityImageView.animationDuration = 1.0f;
_activityImageView.animationRepeatCount = 100;
[_activityImageView startAnimating];
}
- (void)dismissActivity {
[_activityImageView stopAnimating];
[_activityImageView removeFromSuperview];
_activityImageView = nil;
}