图片切换 及 关于 CATransition的动画效果类型
2012-07-17 20:48
423 查看
- (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 上下翻转效果
相关文章推荐
- CATransition的动画效果类型及实现方法--老代码备用参考
- CATransition的动画效果类型及实现方法
- UI -- CATransition的动画效果类型及实现方法
- 淘宝首页 图片滑动切换效果 基于CSS3的transition方法实现
- 图片切换马赛克动画效果
- android app引导页(背景图片切换加各个页面动画效果)
- 札记:翻译-使用Scene和Transition实现【场景切换】动画效果
- Android之app引导页(背景图片切换加各个页面动画效果)
- jQuery图片切换动画效果
- app引导页(背景图片切换加各个页面动画效果)
- 转场动画 CATransition ,效果惊人
- app引导页(背景图片切换加各个页面动画效果)
- jQuery演示10种不同的切换图片列表动画效果
- jQuery演示10种不同的切换图片列表动画效果
- Activity切换时动画(animate)效果实现(overridePendingTransition)
- 关于界面切换,动画效果问题
- 关于Activity切换动画(overridePendingTransition)的黑色背景问题
- CATransition完成几种动画效果
- Android 动画--> 图片切换效果
- jquery上下页面视差滚动切换效果|强大的视差响应动画滑动图片切换效果