1.创建SingleView项目:
1)IOS,SingleView:
2)UseAutomaticReferenceCounting:
2.添加依赖框架:
1)项目,BuildPhases,LBWL:
2)QuartzCore.framework:
3.添加演出用的图片:
4.声明演员:
5.创建舞台:
1)放入两组按钮和4个ImageView:
2)添加关联:
3)设置演员:
6.初始化演出方案:
//// CVUViewController.m// 0716-AnimationAdvanced//// Created by vigiles on 13-7-16.// Copyright (c) 2013年 vigiles. All rights reserved.//#import "CVUViewController.h"@interface CVUViewController ()@end@implementation CVUViewController/* 上面的4个按钮控制的动画 */-(IBAction)doAnimationPaper:(id)sender{ //不适用QuartzCore //1.配置 CGContextRef context = UIGraphicsGetCurrentContext(); //2.播放 [UIView beginAnimations:nil context:context]; //3.缓动 [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; //4.时长 [UIView setAnimationDuration:1]; //5.类型 NSString * title = [sender titleForState:UIControlStateNormal]; //6.如果点击“left”按钮 if ([title isEqualToString:@"left"]) { [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; } if ([title isEqualToString:@"right"]) { [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; } if ([title isEqualToString:@"up"]) { [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; } if ([title isEqualToString:@"down"]) { [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES]; } //7.演员编号 NSInteger one = [[self.view subviews]indexOfObject:self.imgViewOne]; NSInteger two = [[self.view subviews]indexOfObject:self.imgViewTwo]; NSInteger three = [[self.view subviews]indexOfObject:self.imgViewThree]; NSInteger four = [[self.view subviews]indexOfObject:self.imgViewFour]; //8.按编号切换顺序 [self.view exchangeSubviewAtIndex:one withSubviewAtIndex:two]; [self.view exchangeSubviewAtIndex:two withSubviewAtIndex:three]; [self.view exchangeSubviewAtIndex:three withSubviewAtIndex:four]; //9.委托 [UIView setAnimationDelegate:self]; //10.关闭 [UIView commitAnimations]; }/* 下面的4个按钮控制的动画 */-(IBAction)doAnimationAdvan:(id)sender{ //1.创建一个动画对象 CATransition * trsCube = [CATransition animation]; //2.委托 trsCube.delegate=self; //3.时间 trsCube.duration=1; //4.缓动。以下的效果似乎没差别 //trsCube.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; //trsCube.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; //trsCube.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; trsCube.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; //trsCube.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]; //5.类型,type trsCube.type=@"cube"; //立方体,分上下左右 //trsCube.type=@"suckEffect"; //吸收 //trsCube.type=@"oglFlip"; //翻转 //trsCube.type=@"rippleEffect"; //波纹 //trsCube.type=@"pageCurl"; //翻页 //trsCube.type=@"pageUnCurl"; //反翻页 //trsCube.type=kCATransitionFade; //淡化 //trsCube.type=kCATransitionPush; //推挤 //trsCube.type=kCATransitionReveal; //揭开 //trsCube.type=kCATransitionMoveIn; //覆盖 //trsCube.type=@"cameraIrisHollowOpen"; //镜头开 //6.方向,subtype NSString * title = [sender titleForState:UIControlStateNormal]; if ([title isEqualToString:@"left"]) { trsCube.subtype=kCATransitionFromLeft; } if ([title isEqualToString:@"right"]) { trsCube.subtype=kCATransitionFromRight; } if ([title isEqualToString:@"top"]) { trsCube.subtype=kCATransitionFromTop; } if ([title isEqualToString:@"down"]) { trsCube.subtype=kCATransitionFromBottom; } //7. 4个演员的编号 NSInteger one = [[self.view subviews]indexOfObject:self.imgViewOne]; NSInteger two = [[self.view subviews]indexOfObject:self.imgViewTwo]; NSInteger three = [[self.view subviews]indexOfObject:self.imgViewThree]; NSInteger four = [[self.view subviews]indexOfObject:self.imgViewFour]; //8.切换顺序 [self.view exchangeSubviewAtIndex:one withSubviewAtIndex:two]; [self.view exchangeSubviewAtIndex:two withSubviewAtIndex:three]; [self.view exchangeSubviewAtIndex:three withSubviewAtIndex:four]; //[self.view exchangeSubviewAtIndex:four withSubviewAtIndex:one]; //禁止 //9.开播创建的动画 [[self.view layer] addAnimation:trsCube forKey:@"trsCube"];}@end
7.演出:
- end