效果如下:在页面加载时会以一个动画形式展现,停留的时间长短可以控制,时间过后会慢慢消失。。。
实现代码如下: * 显示最新的数量 * * @param count 最新的数量 */ - (void)showNewStatusCount:(NSUInteger)count { // 刷新成功(清空图标数字)-----清空tabbar的提醒数字 self.tabBarItem.badgeValue = nil; [UIApplication sharedApplication].applicationIconBadgeNumber = 0; // 1.创建label UILabel *label = [[UILabel alloc] init]; //label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"timeline_new_status_background"]]; label.backgroundColor = [UIColor redColor]; label.width = [UIScreen mainScreen].bounds.size.width; label.height = 35; // 2.设置其他属性 if (count == 0) { label.text = @"没有新的数据,稍后再试"; } else { label.text = [NSString stringWithFormat:@"共有%zd条新的数据", count]; } label.textColor = [UIColor whiteColor]; label.textAlignment = NSTextAlignmentCenter; label.font = [UIFont systemFontOfSize:16]; // 3.添加 label.y = 64 - label.height; // 将label添加到导航控制器的view中,并且是盖在导航栏下边 [self.navigationController.view insertSubview:label belowSubview:self.navigationController.navigationBar]; // 4.动画 // 先利用1s的时间,让label往下移动一段距离 CGFloat duration = 1.0; // 动画的时间 [UIView animateWithDuration:duration animations:^{ label.transform = CGAffineTransformMakeTranslation(0, label.height); } completion:^(BOOL finished) { // 延迟1s后,再利用1s的时间,让label往上移动一段距离(回到一开始的状态) CGFloat delay = 2.0; // 延迟1s // UIViewAnimationOptionCurveLinear:匀速 [UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveLinear animations:^{ label.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { [label removeFromSuperview]; }]; }]; // 如果某个动画执行完毕后,又要回到动画执行前的状态,建议使用transform来做动画 }
- 欢迎各位一块学习,提高逼格!
也可以添加洲洲哥的微信公众号
更多消息
更多信iOS开发信息 请以关注洲洲哥 的微信公众号,不定期有干货推送: