展示有新的数据的时候从顶部弹出一个提示,然后就消失了
//弹出提示
[self showNewStatusesCount:self.dataArray.count];
#pragma mark 自定义代码
- (void)showNewStatusesCount:(NSInteger)count
{
// 1.创建一个UILabel
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:12];
// 2.显示文字
if (count) {
label.text = [NSString stringWithFormat:@"共有%ld条实例数据", count];
} else {
label.text = @"没有最新的数据";
}
// 3.设置背景
label.backgroundColor = [UIColor colorWithRed:254/255.0 green:129/255.0 blue:0 alpha:1.0];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
// 4.设置frame
label.width = self.view.frame.size.width;
label.height = 35;
label.x = 0;
label.y = CGRectGetMaxY([self.navigationController navigationBar].frame) - label.frame.size.height;
// 5.添加到导航控制器的view
//[self.navigationController.view addSubview:label];
[self.navigationController.view insertSubview:label belowSubview:self.navigationController.navigationBar];
// 6.动画
CGFloat duration = 0.75;
//label.alpha = 0.0;
[UIView animateWithDuration:duration animations:^{
// 往下移动一个label的高度
label.transform = CGAffineTransformMakeTranslation(0, label.frame.size.height);
} completion:^(BOOL finished) { // 向下移动完毕
// 延迟delay秒后,再执行动画
CGFloat delay = 1.0;
[UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:^{
// 恢复到原来的位置
label.transform = CGAffineTransformIdentity;
//label.alpha = 0.0;
} completion:^(BOOL finished) {
// 删除控件
[label removeFromSuperview];
}];
}];
}