AppDelegate.m文件中设置根控制器
RootViewController.m主代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIView * myview = [[[NSBundle mainBundle] loadNibNamed:@"test" owner:nil options:nil] lastObject];
myview.frame = CGRectMake(60, 100, 200, 200);
myview.tag = 2014;
[self.view addSubview:myview];
UIView *sub1 = [[UIView alloc] initWithFrame:myview.bounds];
sub1.backgroundColor = [UIColor yellowColor];
[myview addSubview:sub1];
[sub1 release];
UIView *sub2 = [[UIView alloc] initWithFrame:myview.bounds];
sub2.backgroundColor = [UIColor redColor];
[myview addSubview:sub2];
[sub2 release];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//获得一个动画对象
CATransition *animation = [CATransition animation];
//设置动画时间
animation.duration = 1;
//设置动画速率
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
/*
animation.type = @"cube" //立方体效果
animation.type = @"suckEffect" //收缩效果,如一块布被抽走
animation.type = @"oglFlip" //上下翻转效果
animation.type = @"rippleEffect" //滴水效果
animation.type = @"pageCurl" //向上翻一页
animation.type = @"pageUnCurl" //向下翻一页
*/
//设置动画类型
animation.type = @"pageCurl";
//设置动画子类型
animation.subtype = kCATransitionFromTop;
UIView *myView = [self.view viewWithTag:2014];
[myView.layer addAnimation:animation forKey:@"animation"];
[myView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
}