UIKit 图片的移动、位移、旋转、缩放、翻转、翻页等特效的使用
2013-07-21 20:44
597 查看
UIKit 图片的移动、位移、旋转、缩放、翻转、翻页等特效的使用
OC的UIKit的框架,提供了许多对图片的出来函数,在这里只做几种简单的图片处理特效。
一边情况下 ,移动imageview 只需要改变它的frame属性,frame是CGRect结构体类型的,有 X,Y,W,H。改变他图片就会移动,而且还是做相应的缩放。为了添加渐变过程,就需要下面几个函数了。
[UIView beginAnimations:@"气球" context:@"移动"] ; //开始动画 两个参数是随便传的(因为到现在我也不知道 到底有什么用。)
[UIView setAnimationDuration:2] ;//动画在整个过程 持续 2秒
[UIView commitAnimations] ;// 提交动画 结束的意思。所有的动画操作都是在个函数之前完成的 。
CGAffineTransform aff ;
位移函数
aff = CGAffineTransformTranslate(imageView.transform, 20, 20) ;
旋转函数
CGAffineTransformRotate(imageView.transform, M_PI / 6) ;
缩放函数 1.2 ,1.2 为对imageView 放大 x y 分别放大 1.2倍。如果小于1 为缩小。
aff = CGAffineTransformScale(imageView.transform, 1.2, 1.2) ;
图片的左右翻转
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:imageView cache:YES] ;
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:imageView cache:YES] ;
图片的上下翻页特效
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:imageView cache:YES] ;
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:imageView cache:YES] ;
去除所有的特效
CGAffineTransform aff = CGAffineTransformIdentity ;
下面是部分源码
UIViewController.h 文件
UIViewControll.h 文件
2013-7-20 北京 石景山区
OC的UIKit的框架,提供了许多对图片的出来函数,在这里只做几种简单的图片处理特效。
一边情况下 ,移动imageview 只需要改变它的frame属性,frame是CGRect结构体类型的,有 X,Y,W,H。改变他图片就会移动,而且还是做相应的缩放。为了添加渐变过程,就需要下面几个函数了。
[UIView beginAnimations:@"气球" context:@"移动"] ; //开始动画 两个参数是随便传的(因为到现在我也不知道 到底有什么用。)
[UIView setAnimationDuration:2] ;//动画在整个过程 持续 2秒
[UIView commitAnimations] ;// 提交动画 结束的意思。所有的动画操作都是在个函数之前完成的 。
CGAffineTransform aff ;
位移函数
aff = CGAffineTransformTranslate(imageView.transform, 20, 20) ;
旋转函数
CGAffineTransformRotate(imageView.transform, M_PI / 6) ;
缩放函数 1.2 ,1.2 为对imageView 放大 x y 分别放大 1.2倍。如果小于1 为缩小。
aff = CGAffineTransformScale(imageView.transform, 1.2, 1.2) ;
图片的左右翻转
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:imageView cache:YES] ;
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:imageView cache:YES] ;
图片的上下翻页特效
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:imageView cache:YES] ;
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:imageView cache:YES] ;
去除所有的特效
CGAffineTransform aff = CGAffineTransformIdentity ;
下面是部分源码
UIViewController.h 文件
#import <UIKit/UIKit.h> @interface ViewController : UIViewController { UIImageView *qq ,*bird; BOOL type ; } @end
UIViewControll.h 文件
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. qq = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 166, 232)] ; qq.image = [UIImage imageNamed:@"/2.png"] ; [self.view addSubview:qq] ; bird = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, 45, 36)]; bird.image = [UIImage imageNamed:@"/1.png"] ; [qq addSubview:bird] ; NSArray *btnName = [NSArray arrayWithObjects:@"移动",@"位移",@"旋转",@"放大",@"翻转",@"翻页",@"复原",nil] ; for(int i =1; i< 8; i++) { UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect] ; btn.tag = i ; [btn setTitle:[btnName objectAtIndex:i-1] forState:UIControlStateNormal] ; btn.frame = CGRectMake(255, 30+60*(i -1), 60, 30) ; [self.view addSubview:btn] ; [btn addTarget:self action:@selector(doMove:) forControlEvents:UIControlEventTouchUpInside] ; } type = YES ; UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"正向",@"反向", nil]] ; segment.frame = CGRectMake(80, 370, 100, 30) ; segment.selectedSegmentIndex = 0 ; [segment addTarget:self action:@selector(changeType) forControlEvents:UIControlEventValueChanged] ; [self.view addSubview:segment] ; } -(void) changeType { type = type?NO:YES ; } -(void)doMove:(UIButton*)sender { [UIView beginAnimations:@"气球" context:@"移动"] ; [UIView setAnimationDuration:2] ; CGAffineTransform aff ; switch (sender.tag) { case 1://移动改变位置和大小 if(type) bird.frame = CGRectMake(150, 80, 80, 60) ; else bird.frame = CGRectMake(0, 100, 45, 36) ; break; case 2://位移 , 只 改变位置 { [UIView setAnimationDuration:2] ; if(type) aff = CGAffineTransformTranslate(qq.transform, 20, 20) ; else aff = CGAffineTransformTranslate(qq.transform, -20, -20) ; [qq setTransform:aff] ; } break; case 3://旋转 { if(type) aff = CGAffineTransformRotate(qq.transform, M_PI / 6) ; else aff = CGAffineTransformRotate(qq.transform, -M_PI / 6) ; [qq setTransform:aff] ; } break; case 4:// 缩放 ,倍数 大于 1 即放大 小于 1 缩小 { if(type) aff = CGAffineTransformScale(qq.transform, 1.2, 1.2) ; else aff = CGAffineTransformScale(qq.transform, 1/1.2, 1/1.2) ; [qq setTransform:aff] ; } break; case 5:// 翻转 if(type) [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:qq cache:YES] ; else [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:qq cache:YES] ; break; case 6://翻页 if(type) [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:qq cache:YES] ; else [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:qq cache:YES] ; break; case 7: { CGAffineTransform aff = CGAffineTransformIdentity ; [qq setTransform:aff] ; bird.frame = CGRectMake(0, 100, 45, 36) ; } break; default: break; } [UIView commitAnimations] ; }
2013-7-20 北京 石景山区
相关文章推荐
- WPF图片控件的旋转、缩放、翻转
- WPF图片控件的旋转、缩放、翻转
- Android-补间动画基本使用(位移、缩放、旋转、透明)
- CABasicAnimation的使用方法(移动,旋转,缩放)
- 使用Matrix 显示旋转和缩放后的图片
- unity使用鼠标控制移动、缩放、旋转
- WPF图片控件的旋转、缩放、翻转
- 【Unity3D API的学习与使用】Unity实现GUI组件的位移、缩放和旋转
- WPF 图片文件 旋转、缩放、翻转
- android 实现图片旋转,移动,缩放,并且记录变化值,用另外一张图片显示出来
- PHP图片处理类实现缩放、剪切、相框、水印、锐化、旋转、翻转、透明度、反色等功能
- 跟KingDZ学HTML5之七 探究Canvas之各种特效---移动、旋转、缩放
- Objective-c UIView的,翻转、旋转,偏移,翻页,缩放,取反的动画效果
- Android图片旋转,缩放,位移,倾斜,对称完整示例(一)——imageView.setImageMatrix(matrix)和Matrix
- Android matrix 控制图片的旋转、缩放、移动
- Android图片旋转,缩放,位移,倾斜,对称完整示例(一)——imageView.setImageMatrix(matrix)和Matrix .
- WPF 图片文件 旋转、缩放、翻转
- 使用jQuery实现鼠标滑过图片移动特效
- UIImageView实现图片移动,缩放、旋转的代码片段
- php学习笔记(十六)图片的处理缩放、旋转、透明、锐化、翻转、裁剪