在ios中使用CoreAnimation加入动画

使用前要在build phases中加入QuartzCore.framework

还要#import <QuartzCore/QuartzCore.h>

 

在我的代码中,newView和self.currentView应该是frame相同,两个叠在一起的,执行前new在下current在上

重叠可以用[self.view insertSubview:newView atIndex:0];实现

 1  // 使用Core Animation创建动画
 2         
 3         // 创建CATransition对象
 4         CATransition *animation = [CATransition animation];
 5         
 6         animation.delegate = self;
 7         // 设定动画时间
 8         animation.duration = 0.3;
 9         // 设定动画快慢(开始与结束时较慢)
10         animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
11 
12             animation.type = kCATransitionMoveIn;
13             animation.subtype = kCATransitionFromRight;
14         
15 
16         NSUInteger newIndex = [[self.view subviews] indexOfObject:newView];
17         NSUInteger oldIndex = [[self.view subviews] indexOfObject:self.currentView];
18         [self.view exchangeSubviewAtIndex:newIndex withSubviewAtIndex:oldIndex];
19          [[self.view layer] addAnimation:animation forKey:@"animation"];

ThanksTo https://github.com/iimgal/StudyiOS

posted on 2012-12-04 10:45  Entreri  阅读(199)  评论(0)    收藏  举报