天天看點

新浪微部落格戶端(19)-顯示重新整理的最新微網誌數量

HomeViewController.m

/** 顯示重新整理微網誌數量 */
- (void)showRefreshStatusesNums:(NSUInteger)nums {

    // 1. 建立提示label
    UILabel *label = [[UILabel alloc] init];
    label.width = [UIScreen mainScreen].bounds.size.width;
    label.height = 35;
    label.x = 0;
    label.y = 64 - label.height;
    label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"timeline_new_status_background"]];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:16];
    
    if (nums == 0) {
        label.text = @"沒有新的微網誌資料";
    } else {
        label.text = [NSString stringWithFormat:@"重新整理了%zd條微網誌資料",nums];
    }
    
    // 2. 将目前label添加navigationBar的下面
    [self.navigationController.view insertSubview:label belowSubview:self.navigationController.navigationBar];
    
    // 2. 執行動畫
    CGFloat duration = 1.0;
    [UIView animateWithDuration:duration animations:^{
        label.transform = CGAffineTransformMakeTranslation(0, label.height);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:duration delay:duration options:UIViewAnimationOptionCurveEaseInOut animations:^{
            label.transform = CGAffineTransformIdentity; // 清空目前transform
        } completion:^(BOOL finished) {
            [label removeFromSuperview]; // 清空目前label
        }];
    }];
    

}      

最終效果:

新浪微部落格戶端(19)-顯示重新整理的最新微網誌數量