Snail—UI学习之动画Animations
来源:互联网 发布:漓江学院 知乎 编辑:程序博客网 时间:2024/05/22 06:18
直接上代码,看的不深,以后再做详细讲解
#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
0 0
- Snail—UI学习之动画Animations
- Snail—UI学习之初识
- Snail—UI学习之UILabel
- Snail—UI学习之UIButton
- Snail—UI学习之UITextField
- Snail—UI学习之进度条UIProgressView
- Snail—UI学习之UISegmentControl
- Snail—UI学习之开关UISwith
- Snail—UI学习之工具栏UIToolBar
- Snail—UI学习之UITableView之分组显示
- Snail—UI学习之UITableView之自定义UITableViewCell
- Snail—UI学习之得到某组件的方法
- Snail—UI学习之UIImage及UIImageView
- Snail—UI学习之自定义通知NSNotification
- Snail—UI学习之导航视图控制器UINavigationController(系统)
- Snail—UI学习之自定义导航栏NSNavigationController
- Snail—UI学习之代理传值Delegate
- Snail—UI学习之滑块UISlider
- web001-html,css,js
- PHP libcurl使用总结
- vpngate 的使用
- Git的Patch功能
- ios开发之MVC模式理解
- Snail—UI学习之动画Animations
- OC基础回顾(七)Foundation Kit 框架
- C# TreeView的使用以及节点的拖动
- 有向图的强连通分量(SCC)
- XMPP的基础知识
- Objective-C学习笔记(四)——OC实现最简单的数学运算
- 42. Trapping Rain Water
- Spring(二)编码剖析Spring对JavaBean的管理
- Android API Guides 阅读笔记(1)----Application Fundamentals