博客> MJRefreshHeader 重写--头部动画加载显示
MJRefreshHeader 重写--头部动画加载显示
2017-12-14 16:26 评论:0 阅读:284 lvhahaha
MJRefreshHeader 头部动画刷新

头部刷新的时候加载一个动画,其实就是继承与MJRefreshHeader,然后添加一些控件,做成基本的帧动画。使用的时候,直接使用这个类就行。 直接上代码。

.h文件中

@interface EPRefreshHeader : MJRefreshHeader

@end

.m文件中

@interface EPRefreshHeader ()

@property (nonatomic, strong) UILabel label; @property (nonatomic, strong) UIImageView logo;

@end

@implementation EPRefreshHeader

  • 重写方法 在这里做一些初始化配置(比如添加子控件)
  • (void)prepare { [super prepare];

    // 设置控件的高度 self.mj_h = 50;

    // 添加label UILabel *label = [[UILabel alloc] init]; label.textColor = [UIColor lightGrayColor]; label.font = [UIFont boldSystemFontOfSize:16]; label.textAlignment = NSTextAlignmentCenter; [self addSubview:label]; self.label = label;

    // logo // UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Logo"]]; // logo.image = [UIImage imageNamed:@"loading_list_0"]; // logo.contentMode = UIViewContentModeScaleAspectFit; // [self addSubview:logo]; // self.logo = logo;

// NSMutableArray images = [[NSMutableArray alloc] init]; // for (int i = 0; i < 11; i++) { // UIImage image = [UIImage imageNamed:[NSString stringWithFormat:@"loadinglist%d", i]]; // [images addObject:image]; // } //
// self.logo.animationImages = images; // [self.logo startAnimating]; }

在这里设置子控件的位置和尺寸

  • (void)placeSubviews { [super placeSubviews];

    // self.label.frame = self.bounds;

// self.logo.bounds = CGRectMake(0, 0, 20, 20); // self.logo.center = CGPointMake((self.mj_w - 75) 0.5, self.mj_h 0.5);

self.label.frame = CGRectMake(0, 0, 120, self.mj_h);

self.label.textAlignment = NSTextAlignmentLeft;
self.label.font = [UIFont systemFontOfSize:14];

}

监听scrollView的contentOffset改变

  • (void)scrollViewContentOffsetDidChange:(NSDictionary *)change { [super scrollViewContentOffsetDidChange:change];

}

监听scrollView的contentSize改变

  • (void)scrollViewContentSizeDidChange:(NSDictionary *)change { [super scrollViewContentSizeDidChange:change];

}

监听scrollView的拖拽状态改变

  • (void)scrollViewPanStateDidChange:(NSDictionary *)change { [super scrollViewPanStateDidChange:change];

}

监听控件的刷新状态

  • (void)setState:(MJRefreshState)state { MJRefreshCheckState;

    switch (state) { case MJRefreshStateIdle: self.label.text = @"下拉刷新"; // [self.logo stopAnimating]; // self.logo.hidden = YES; break; case MJRefreshStatePulling: // self.label.text = @"松开刷新"; // self.logo.hidden = YES; break; case MJRefreshStateRefreshing: self.label.text = @"加载中..."; // [self.logo startAnimating]; // self.logo.hidden = NO; break; default: break; } }

    监听拖拽比例(控件被拖出来的比例)

  • (void)setPullingPercent:(CGFloat)pullingPercent { [super setPullingPercent:pullingPercent];

    // 1.0 0.5 0.0 // 0.5 0.0 0.5 // CGFloat red = 1.0 - pullingPercent 0.5; // CGFloat green = 0.5 - 0.5 pullingPercent; // CGFloat blue = 0.5 * pullingPercent; // self.label.textColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0]; }

@end 这样以后直接使用就好了了。

收藏
1
sina weixin mail 回到顶部