輕量型指示層-SCProgressHUD

別問我問為什么不用MBProgressHUD和SVProgressHUD,MBProgressHUD和SVProgressHUD固然好,但不是自己做的,總有種超脫自己控制的感覺,有時候顯得不夠靈活,考慮到自己項目的情況做了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;
}

顯示的動畫用的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"];

動畫消失后調(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是配合我們的項目來做的,若要引用到其他項目可在此基礎(chǔ)略作修改。

項目地址:GitHub

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容