新浪微博客户端(19)-显示刷新的最新微博数量

本文介绍了一个iOS应用中用于显示刷新微博数据数量的方法。通过自定义UILabel并使用UIView动画实现从导航栏下方出现并逐渐上移直至消失的效果。该方法能够清晰地告知用户刷新了多少条新的微博数据。

 

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
        }];
    }];
    

}

 

最终效果:

 

转载于:https://www.cnblogs.com/yongdaimi/p/6036097.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值