最简单的方式是通过一个UILabel来实现,将其添加到导航条下面,然后就是添加动画了.需要注意的是 UIView的方法
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
和仿射变换
CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty)(平移:设置平移量)
CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)(缩放:设置缩放比例)
CGAffineTransformMakeRotation(CGFloat angle)(旋转:设置旋转角度)
仿射变换针对视图的原定最初位置的中心点为起始参照进行相应操作的
view.transform=CGAffineTransformIdentity; // 仿射变换还原
代码如下:
- (void)showNewDataCount:(int)count
{
if (count == 0) return;
// 展示最新的微博数
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;
// 插入导航控制器下导航条下面
[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];
}];
}];
}










网友评论