展示有新的數(shù)據(jù)的時候從頂部彈出一個提示,然后就消失了
//彈出提示
[self showNewStatusesCount:self.dataArray.count];
#pragma mark 自定義代碼
- (void)showNewStatusesCount:(NSInteger)count
{
// 1.創(chuàng)建一個UILabel
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:12];
// 2.顯示文字
if (count) {
label.text = [NSString stringWithFormat:@"共有%ld條實例數(shù)據(jù)", count];
} else {
label.text = @"沒有最新的數(shù)據(jù)";
}
// 3.設(shè)置背景
label.backgroundColor = [UIColor colorWithRed:254/255.0 green:129/255.0 blue:0 alpha:1.0];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
// 4.設(shè)置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.添加到導(dǎo)航控制器的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秒后,再執(zhí)行動畫
CGFloat delay = 1.0;
[UIView animateWithDuration:duration delay:delay options:UIViewAnimationOptionCurveEaseInOut animations:^{
// 恢復(fù)到原來的位置
label.transform = CGAffineTransformIdentity;
//label.alpha = 0.0;
} completion:^(BOOL finished) {
// 刪除控件
[label removeFromSuperview];
}];
}];
}