从下往上增加的柱状图生成动画(适用于统计类应用)
2014-06-17 15:59
197 查看
我们在一些统计,理财应用中,经常能看到很多的柱状图,用来直观的标注信息,最近一个朋友刚好在做这方面的应用,跑来问我这个怎么实现,我笑他不就是简单的实现一个动画嘛,额,然后自己去做的时候才发现各种坑.
1.所有的UIView子类中,UILabel不能实现效果
2.创建View和对View实现的动画效果要放在一个方法中
3.增加的height和减少的top(顶部y坐标)必须成2倍关系 或者 增加的height和增加的bottom(底部y坐标)必须成2倍关系
@最后,直接上代码,大家可以去试验下,我也不太清楚究竟是什么原理,有了解的欢迎给我留言
1.所有的UIView子类中,UILabel不能实现效果
2.创建View和对View实现的动画效果要放在一个方法中
3.增加的height和减少的top(顶部y坐标)必须成2倍关系 或者 增加的height和增加的bottom(底部y坐标)必须成2倍关系
@最后,直接上代码,大家可以去试验下,我也不太清楚究竟是什么原理,有了解的欢迎给我留言
#import "HMTRootViewController.h" #import "UIViewAdditions.h" @interface HMTRootViewController () @property (nonatomic, strong)NSMutableArray *imageArray; @property (nonatomic, strong)NSArray *urlArray; @property (nonatomic, strong)UIView *columnarView; // 柱状图 @end @implementation HMTRootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. #pragma mark - 一个bug,创建view必须和动画增高在同一个方法里面 self.columnarView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 40, 10)]; self.columnarView.backgroundColor = [UIColor redColor]; [self.view addSubview:_columnarView]; // 用来对比,columnarView是否发生了偏移 UIView *aa = [[UIView alloc] initWithFrame:CGRectMake(50, 150, 40, 10)]; aa.backgroundColor = [UIColor brownColor]; [self.view addSubview:aa]; UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem]; button.frame = CGRectMake(100, 510, 80, 40); [button setTitle:@"生成" forState:UIControlStateNormal]; [button addTarget:self action:@selector(onClickTextButton) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; [UIView animateWithDuration:2 animations:^{ // 增加的height和减少的top(顶部y坐标)必须成2倍关系,才能保持动画的一致 self.columnarView.height += 100; self.columnarView.top -= 50; } completion:^(BOOL finished) { }]; } - (void)onClickTextButton{ self.columnarView = [[UIView alloc] initWithFrame:CGRectMake(150, 100, 40, 10)]; self.columnarView.backgroundColor = [UIColor redColor]; [self.view addSubview:_columnarView]; [UIView animateWithDuration:2 animations:^{ // 增加的height和增加的bottom(底部y坐标)必须成2倍关系,才能保持动画的一致 self.columnarView.height += 100; self.columnarView.bottom = 160; // self.columnarView.bottom += 50 不能实现 } completion:^(BOOL finished) { }]; }
相关文章推荐
- 从下往上增加的柱状图生成动画(适用于统计类应用)
- 使用JFreeChart生成柱状图,不做任何注释,只求应用,生成的柱状图放在D:\\fruit.jpg
- Struts2 默认UI组件 s:form 生成代码不适用于使用二级域名情况的应用
- jfreechart应用_经典例题_生成饼状图、生成单组柱状图、生成多组柱状图、生成堆积柱状图、生成折线图
- 使用JFreeChar生成柱状图,不做任何注释,只求应用,生成的柱状图输出到网页中
- Android应用内截动画生成Gif
- jfreechart应用_经典例题_生成饼状图、生成单组柱状图、生成多组柱状图、生成堆积柱状图...
- 最小生成树的应用--城市高速公路问题
- JSP调用JavaBean在网页上动态生成柱状图
- JSP调用JavaBean在网页上动态生成柱状图(转 )
- 用JAVA生成GIF动画
- iTextSharp生成的PDF显示“Page X of Y”的效果,IPdfPageEvent的应用一例
- sudoku游戏1.1版(增加了生成初始棋局的功能)
- .Net中应用XML动态生成窗体
- 基于模板和XML在BS结构应用中生成word文件
- 用JAVA生成GIF动画
- 个性化Microsoft Data Access V2.0以适用于应用系统开发
- JSP调用Java Bean在网页上动态生成柱状图
- 试卷自动生成系统的开发与应用
- ASP.NET GDI+生成动态的Gif动画.