別問我問為什么不用MBProgressHUD和SVProgressHUD,MBProgressHUD和SVProgressHUD固然好盹憎,但不是自己做的拒贱,總有種超脫自己控制的感覺耕蝉,有時(shí)候顯得不夠靈活崔梗,考慮到自己項(xiàng)目的情況做了SCProgressHUD。
SCProgressHUD.gif
SCProgressHUD結(jié)構(gòu)
- 顯示
+ (void)showMsg:(NSString *)msg inView:(UIView*)theView afterDelay:(NSTimeInterval)delay completed:(ShowCompleted)completedBlock
{
SCProgressHUD *alert = [[SCProgressHUD alloc] initWithMsg:msg];
if (!theView){
[[self getUnhiddenFrontWindowOfApplication] addSubview:alert];
}
else{
[[SCProgressHUD getWindow] addSubview:alert];
}
[alert showAlertWithMsg:delay];
[alert completed:completedBlock];
}
- (void)completed:(ShowCompleted)completedBlock{
self.completedBlock = completedBlock;
}
顯示的動(dòng)畫用的CAKeyframeAnimation
CAKeyframeAnimation* scaleAnimation =[CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.duration = kDefaultDuration;
scaleAnimation.cumulative = YES;
scaleAnimation.repeatCount = 1;
scaleAnimation.removedOnCompletion = NO;
scaleAnimation.fillMode = kCAFillModeForwards;
scaleAnimation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:self.animationTopScale],
[NSNumber numberWithFloat:1.0f],
[NSNumber numberWithFloat:1.0f],
[NSNumber numberWithFloat:1.0],
nil];
scaleAnimation.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:0.085f],
[NSNumber numberWithFloat:0.92f],
[NSNumber numberWithFloat:1.0f], nil];
scaleAnimation.timingFunctions = [NSArray arrayWithObjects:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil];
CAAnimationGroup *group = [CAAnimationGroup animation];
group.duration = duration;
group.delegate = self;
group.animations = [NSArray arrayWithObjects:scaleAnimation, nil];
[self.layer addAnimation:group forKey:@"group"];
動(dòng)畫消失后調(diào)用回調(diào)
self.completedBlock();
[self removeFromSuperview];
- HUD隱藏
+ (BOOL)hideHUDForView:(UIView *)view
{
SCProgressHUD *hud = [self HUDForView:view];
if (hud != nil) {
UIWindow *window;
if (!view){
window = [self getUnhiddenFrontWindowOfApplication];
}
else{
window = [SCProgressHUD getWindow];
}
UIView *backgroundView = [window viewWithTag:100];
if (backgroundView) {
[backgroundView removeFromSuperview];
}
[hud hidenHUD];
return YES;
}
return NO;
}
- (void)hidenHUD{
[self.HUDActivity stopAnimating];
[self removeFromSuperview];
}
此HUD是配合我們的項(xiàng)目來做的垒在,若要引用到其他項(xiàng)目可在此基礎(chǔ)略作修改蒜魄。
項(xiàng)目地址:GitHub