您的位置:首页 > 产品设计 > UI/UE

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 文件

#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 北京 石景山区
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: