UIView 动画基本学习
来源:互联网 发布:网络言论自由权的内涵 编辑:程序博客网 时间:2024/06/05 19:01
UIView 可以设置很多动画, 淡入淡出,改变颜色等,只要把这些独立动画合并到一起,就会起到意想不到的效果
创建一个 UIview 添加一个UIButton 当点击button时执行动作。我添加了三个button做不同的动画效果。
前两个button只是普通操作,第三个button使用的是block动画方式, 这两种的区别是普通的动画要写更多的代码,block只是用一行代码实现功能,
但是block里面也可以写入很多设置代码,如设置时间,透明度,执行次数等。
以下就是代码
- (void)viewDidLoad {
[superviewDidLoad];
UIView *view = [[UIViewalloc] initWithFrame:CGRectMake(40,40, 100, 100)];
[view setBackgroundColor:[UIColorgreenColor]];
[viewsetTag:1001];
[self.viewaddSubview:view];
//第一个button
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
button.frame =CGRectMake(10,400, 80, 40);
[button setTitle:@"Do Ani"forState:UIControlStateNormal];
[button addTarget:selfaction:@selector(doAnimations:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
//第二个button
UIButton *button1 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
button1.frame =CGRectMake(100,400, 80, 40);
[button1 setTitle:@"Do Back"forState:UIControlStateNormal];
[button1 addTarget:selfaction:@selector(doTransition:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button1];
//第三个button
UIButton *button2 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
button2.frame =CGRectMake(200,400, 80, 40);
[button2 setTitle:@"Blk ani"forState:UIControlStateNormal];
[button2 addTarget:selfaction:@selector(doBlockAnimation:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button2];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)doAnimations:(UIButton *) button
{
//通过tag值取得当前的view
UIView *view = [self.view viewWithTag:1001];
//开始执行动作代码, 所有动画效果代码都要写在这个 开始和结束动画代码之间
[UIView beginAnimations:nil context:NULL];
//动画过程
[UIView setAnimationDuration:1.5]; //动画时间
[UIView setAnimationRepeatCount:2]; //动画执行次数
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; //动画效果 枚举类型,可以通过API修改其他值
[UIView setAnimationRepeatAutoreverses:YES]; //要不要恢复
view.frame = CGRectMake(60, 200, 170, 110);
//view.alpha = 0.0;
[view setBackgroundColor:[UIColor redColor]]; //改变颜色
[UIView commitAnimations];
}
- (void)doAnimations:(UIButton *) button
{
//通过tag值取得当前的view
UIView *view = [self.view viewWithTag:1001];
//开始执行动作代码, 所有动画效果代码都要写在这个 开始和结束动画代码之间
[UIView beginAnimations:nil context:NULL];
//动画过程
[UIView setAnimationDuration:1.5]; //动画时间
[UIView setAnimationRepeatCount:2]; //动画执行次数
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; //动画效果 枚举类型,可以通过API修改其他值
[UIView setAnimationRepeatAutoreverses:YES]; //要不要恢复
view.frame = CGRectMake(60, 200, 170, 110);
//view.alpha = 0.0;
[view setBackgroundColor:[UIColor redColor]]; //改变颜色
[UIView commitAnimations];
}
- (void)doTransition:(UIButton *) button
{
UIView *view = [self.view viewWithTag:1001];
// [UIView set]
[UIView beginAnimations:nil context:NULL];
//加入翻页效果,也是枚举类型 可以查API, cache的就是说要不要缓存,为了提高运行速度,一般选 YES
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:view cache:YES];
[UIView setAnimationDuration:1.5];
[UIView setAnimationRepeatCount:2];
//自动恢复到位置
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
view.frame = CGRectMake(40, 70, 200, 150);
//view.alpha = 0.0;
[view setBackgroundColor:[UIColor yellowColor]];
[UIView commitAnimations];
}
//通过block进行动画操作, block函数也有几个,只使用其中一个
- (void)doBlockAnimation:(UIButton *)button
{
UIView *view = [self.viewviewWithTag:1001];
// [UIView set]
[UIViewbeginAnimations:nilcontext:NULL];
//第一个参数执行次数, 第二个参数就是动作, 第三个结束后执行什么动作,可以是删除,改变颜色等等
[UIViewanimateWithDuration:2animations:^{
[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:view cache:YES];
[UIViewsetAnimationDuration:5];
[UIViewsetAnimationRepeatCount:4];
//自动恢复到位置
[UIViewsetAnimationRepeatAutoreverses:YES];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];
view.frame =CGRectMake(40,70, 200, 150);
//view.alpha = 0.0;
[view setBackgroundColor:[UIColoryellowColor]];
}completion:^(BOOL finished) {
// [view removeFromSuperview];
}];
[UIViewcommitAnimations];
}
- (void)doAnimations:(UIButton *) button
{
//通过tag值取得当前的view
UIView *view = [self.view viewWithTag:1001];
//开始执行动作代码, 所有动画效果代码都要写在这个 开始和结束动画代码之间
[UIView beginAnimations:nil context:NULL];
//动画过程
[UIView setAnimationDuration:1.5]; //动画时间
[UIView setAnimationRepeatCount:2]; //动画执行次数
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; //动画效果 枚举类型,可以通过API修改其他值
[UIView setAnimationRepeatAutoreverses:YES]; //要不要恢复
view.frame = CGRectMake(60, 200, 170, 110);
//view.alpha = 0.0;
[view setBackgroundColor:[UIColor redColor]]; //改变颜色
[UIView commitAnimations];
}
- (void)doTransition:(UIButton *) button
{
UIView *view = [self.view viewWithTag:1001];
// [UIView set]
[UIView beginAnimations:nil context:NULL];
//
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:view cache:YES];
[UIView setAnimationDuration:1.5];
[UIView setAnimationRepeatCount:2];
//自动恢复到位置
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
view.frame = CGRectMake(40, 70, 200, 150);
//view.alpha = 0.0;
[view setBackgroundColor:[UIColor yellowColor]];
[UIView commitAnimations];
}
- UIView 动画基本学习
- UIView基本动画
- UIView动画学习笔记
- SG之UIView基本动画
- UIView动画(学习笔记)
- iOS 学习笔记 UIView动画
- UIView动画(过渡效果)的学习笔记
- UIView动画(过渡效果)的学习笔记
- UIView动画(过渡效果)的学习笔记
- UIView动画(过渡效果)的学习笔记
- OC学习之UIView动画设置
- UIView动画(过渡效果)的学习笔记
- UIView动画(过渡效果)的学习笔记
- UIView动画(过渡效果)的学习…
- [iOS]UIView动画学习笔记(上)
- [iOS]UIView动画学习笔记(下)
- UIView动画(过渡效果)的学习笔记
- UIView动画(过渡效果)的学习笔记
- 大型网站技术架构
- 资深投资人全力反击: VC增值平台从来就不是一坨狗屎
- python中simplejson模块
- iOS:扫描银行卡识别卡号
- 彻底理解CSS浮动 清除浮动的方法
- UIView 动画基本学习
- 用函数fopen_s打开数据文件
- 9种CSS3 blend模式制作的鼠标滑过图片标题特效
- IOS文档注释
- .net viewstate 与静态变量的优缺点
- html5+jQuery实现数字时钟/模拟时钟
- 关于怎样解决非煤矿山顶板安全监测与地压监测的系统
- android Button粒子化效果
- 深度分析: Google 和 Apple 从来就不是死对头