最簡單的方式是通過一個UILabel來實現(xiàn),將其添加到導(dǎo)航條下面,然后就是添加動畫了.需要注意的是 UIView的方法
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
和仿射變換
CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty)(平移:設(shè)置平移量)
CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)(縮放:設(shè)置縮放比例)
CGAffineTransformMakeRotation(CGFloat angle)(旋轉(zhuǎn):設(shè)置旋轉(zhuǎn)角度)
仿射變換針對視圖的原定最初位置的中心點為起始參照進行相應(yīng)操作的
view.transform=CGAffineTransformIdentity; // 仿射變換還原
代碼如下:
- (void)showNewDataCount:(int)count
{
if (count == 0) return;
// 展示最新的微博數(shù)
CGFloat height = 35;
CGFloat y = CGRectGetMaxY(self.navigationController.navigationBar.frame) - height;
CGFloat x = 0;
CGFloat width = self.view.qy_width;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
label.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"timeline_new_status_background"]];
label.textColor = [UIColor whiteColor];
label.text = [NSString stringWithFormat:@"更新了%d條",count];
label.textAlignment = NSTextAlignmentCenter;
// 插入導(dǎo)航控制器下導(dǎo)航條下面
[self.navigationController.view insertSubview:label belowSubview:self.navigationController.navigationBar];
// 動畫往下面平移
[UIView animateWithDuration:0.25 animations:^{
label.transform = CGAffineTransformMakeTranslation(0, height);
} completion:^(BOOL finished) {
// 往上面平移
[UIView animateWithDuration:0.25 delay:2 options:UIViewAnimationOptionCurveLinear animations:^{
// 還原
label.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[label removeFromSuperview];
}];
}];
}