MJRefreshBackNormalFooter
添加箭頭圖片和刷新時(shí)的轉(zhuǎn)動(dòng)指示器
#pragma mark - 懶加載子控件
- (UIImageView *)arrowView
{
if (!_arrowView) {
UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]];
[self addSubview:_arrowView = arrowView];
}
return _arrowView;
}
- (UIActivityIndicatorView *)loadingView
{
if (!_loadingView) {
UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle];
loadingView.hidesWhenStopped = YES;
[self addSubview:_loadingView = loadingView];
}
return _loadingView;
}
- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle
{
_activityIndicatorViewStyle = activityIndicatorViewStyle;
self.loadingView = nil;
[self setNeedsLayout];
}
#pragma mark - 重寫父類的方法
- (void)prepare
{
[super prepare];
self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
}
- (void)placeSubviews
{
[super placeSubviews];
// 箭頭的中心點(diǎn)
CGFloat arrowCenterX = self.mj_w * 0.5;
if (!self.stateLabel.hidden) {
arrowCenterX -= self.labelLeftInset + self.stateLabel.mj_textWith * 0.5;
}
CGFloat arrowCenterY = self.mj_h * 0.5;
CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY);
// 箭頭
if (self.arrowView.constraints.count == 0) {
self.arrowView.mj_size = self.arrowView.image.size;
self.arrowView.center = arrowCenter;
}
// 圈圈
if (self.loadingView.constraints.count == 0) {
self.loadingView.center = arrowCenter;
}
self.arrowView.tintColor = self.stateLabel.textColor;
}
- (void)setState:(MJRefreshState)state
{
MJRefreshCheckState
// 根據(jù)狀態(tài)做事情
if (state == MJRefreshStateIdle) {
if (oldState == MJRefreshStateRefreshing) {
self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI);
[UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{
self.loadingView.alpha = 0.0;
} completion:^(BOOL finished) {
self.loadingView.alpha = 1.0;
[self.loadingView stopAnimating];
self.arrowView.hidden = NO;
}];
} else {
self.arrowView.hidden = NO;
[self.loadingView stopAnimating];
[UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{
self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI);
}];
}
} else if (state == MJRefreshStatePulling) {
self.arrowView.hidden = NO;
[self.loadingView stopAnimating];
[UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{
self.arrowView.transform = CGAffineTransformIdentity;
}];
} else if (state == MJRefreshStateRefreshing) {
self.arrowView.hidden = YES;
[self.loadingView startAnimating];
} else if (state == MJRefreshStateNoMoreData) {
self.arrowView.hidden = YES;
[self.loadingView stopAnimating];
}
}
總結(jié)赖歌,使用到了transform來(lái)使用一張箭頭圖片進(jìn)行旋轉(zhuǎn)180度民逼,是的有向上或向下的旋轉(zhuǎn)效果