Snail—UI学习之动画Animations
2015-07-22 21:16
459 查看
直接上代码,看的不深,以后再做详细讲解
#import "WJJRootViewController.h" @interface WJJRootViewController (){ //把view设为全局变量 UIView * _view; } @end @implementation WJJRootViewController - (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. self.view.backgroundColor = [UIColor grayColor]; _view = [[UIView alloc] initWithFrame:CGRectMake(300, 400, 20, 20)]; _view.tag = 250; _view.backgroundColor = [UIColor purpleColor]; [self.view addSubview:_view]; //动画执行第一种方法 UIButton * button1 = [UIButton buttonWithType:UIButtonTypeSystem]; button1.tag = 1; button1.frame = CGRectMake(0, 460, 50, 20); button1.backgroundColor = [UIColor yellowColor]; [button1 setTitle:@"动画1" forState:UIControlStateNormal]; [button1 addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button1]; //动画执行第一种方法 UIButton * button2 = [UIButton buttonWithType:UIButtonTypeSystem]; button2.tag = 2; button2.frame = CGRectMake(60, 460, 50, 20); button2.backgroundColor = [UIColor yellowColor]; [button2 setTitle:@"动画2" forState:UIControlStateNormal]; [button2 addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button2]; //动画执行第一种方法 UIButton * button3 = [UIButton buttonWithType:UIButtonTypeSystem]; button3.tag = 3; button3.frame = CGRectMake(120, 460, 50, 20); button3.backgroundColor = [UIColor yellowColor]; [button3 setTitle:@"动画3" forState:UIControlStateNormal]; [button3 addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button3]; } - (void)change:(UIButton *)button{ if (button.tag == 1) { //动画执行前的准备 [UIView beginAnimations:nil context:nil]; //动画执行的时间 [UIView setAnimationDuration:10]; //动画执行的 也就是要看到的动画效果 _view.frame = CGRectMake(0, 20, 50, 50); _view.backgroundColor = [UIColor blackColor]; //动画执行 [UIView commitAnimations]; }else if (button.tag == 2){ //动画持续10s,block中写的就是要实现的最终动画结果 [UIView animateWithDuration:10 animations:^{ _view.frame = CGRectMake(0, 20, 50, 50); _view.backgroundColor = [UIColor blackColor]; }]; }else if (button.tag == 3){ //第一个block是第一次实现的动画效果 第二个block是第一个动画效果完成后执行的另一个动画 [UIView animateWithDuration:4 animations:^{ _view.frame = CGRectMake(0, 20, 50, 50); _view.backgroundColor = [UIColor blackColor]; } completion:^(BOOL finshed){ [UIView animateWithDuration:10 animations:^{ _view.frame = CGRectMake(300, 440, 20, 20); _view.backgroundColor = [UIColor blackColor]; }]; }]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- Android Recovery Ui 分析
- vlc在ubuntu15.04下安装成功(解决sudo apt-get build-dep vlc失败问题)
- setNilValueForKey:could not set nil as the value for the key distance.解决方案
- Snail—UI学习之UIImage及UIImageView
- POJ Blue Jeans 3080【KMP+string】
- hdu 5297 Y sequence 容斥+迭代
- [leedcode 115] Distinct Subsequences
- 第一次写博客,为自己学习apue的每一步做好记录
- [翻译] M13ProgressSuite
- break label和continue label
- [Leetcode]-Unique Paths II
- Message Queue基本使用说明
- 多校第一场 1010 hdu 5297 Y sequence(容斥+二分)
- Snail—UI学习之UIButton实现界面跳转及属性传值
- Snail—UI学习之得到某组件的方法
- HDU 5288 OO’s Sequence(数学啊 多校2015)
- [Leetcode]-Unique Paths
- 每天一个小知识点10(jQuerMobile总结一)
- OO’s Sequence
- 仿JD商城UI布局达到90%