图片切换 及 关于 CATransition的动画效果类型

 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
     if (dirString) 
     {
          CATransition *animation = [self getAnimation:dirString];
          [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
          [[[self superview] layer] addAnimation:animation forKey:kAnimationKey];
     }
}

 

 

 

 

1.两张图片手指触摸  左右上下滑动 实现方法

 

- (CATransition *) getAnimation:(NSString *) direction
{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:@"oglFlip"]; 
[animation setType:kCATransitionPush];    //在下面 有这种动画类型的详细解释
[animation setSubtype:direction];
[animation setDuration:1.0f];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
return animation;
}

 

#define HORIZ_SWIPE_DRAG_MIN 12 
#define VERT_SWIPE_DRAG_MAX 4 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
      UITouch *touch = [touches anyObject]; 
      startTouchPosition = [touch locationInView:self]; dirString = NULL;
} 


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
   if (dirString) 
   {
        CATransition *animation = [self getAnimation:dirString];
        [[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
        [[[self superview] layer] addAnimation:animation forKey:kAnimationKey];
    }
}

 

 

 

 

 

实现iphone的动画效果可以分为两种方法一种是UIView层面的一种是是

使用CATransition进行更低层次的控制 

第一种是UIView,UIView方式可能在低层也是使用CATransition进行

了封装,它只能用于一些简单的、常用的效果展现

 

 

 

 

CGContextRef context = UIGraphicsGetCurrentContext() ;

[UIView beginAnimations:nil context:context];   //开始动画

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 

                               forView:[self superview] cache:YES]; //动画的方向

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  //动画的形式

[UIView setAnimationDuration:1.0];    //动画的速度以秒为单位

[[self superview]exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; 

                                      //转换的固定格式

[UIView commitAnimations];            //也为固定格式

第二种是用CATransition这个方法

这里使用setType和setSubtype组合使用这个比较保险因为他们的参数在官方API中定义

setType可以有四种返回类型

KCATransitionFade   淡出 

KCATransitionMoveIn   从指定的方向用新的图来覆盖旧得图

KCATransitionPush     推出 像观看幻灯片那样从指定的方向例如左  

                      新的图片从左边出来旧的图片向右边去

KCATransitionReveal   从底部显示出来与 MoveIn的效果刚好相反

setSubtype  也有四种返回类型

KCATransitionFromRight             KCATransitionFromLeft (默认值) 
 
KCATransitionFromTop                KCATransitionFromBottom

还有一种设置动画类型的方法 不用setSubtype 只用setType

[animation setType:@"suckEffect"];

这里的suckEffect就是效果名称,可以用的效果主要有:

pageCurl   向上翻一页

pageUnCurl 向下翻一页

rippleEffect 滴水效果

suckEffect收缩效果,如一块布被抽走

cube     立方体效果

oglFlip 上下翻转效果

 

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值