UIKit 图片的移动、位移、旋转、缩放、翻转、翻页等特效的使用

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  北京 石景山区 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值