仿咸魚上拉刷新
#pragma mark - 重寫方法
#pragma mark 在這里做一些初始化配置(比如添加子控件)
- (void)prepare
{
[super prepare];
// 設置控件的高度
self.mj_h = 50;
}
#pragma mark 在這里設置子控件的位置和尺寸
- (void)placeSubviews
{
[super placeSubviews];
}
#pragma mark 監(jiān)聽scrollView的contentOffset改變
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
{
[super scrollViewContentOffsetDidChange:change];
}
#pragma mark 監(jiān)聽scrollView的contentSize改變
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
{
[super scrollViewContentSizeDidChange:change];
}
#pragma mark 監(jiān)聽scrollView的拖拽狀態(tài)改變
- (void)scrollViewPanStateDidChange:(NSDictionary *)change
{
[super scrollViewPanStateDidChange:change];
}
#pragma mark 監(jiān)聽控件的刷新狀態(tài)
- (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;
}