将CATransition动画添加到UIViewControllers

时间:2012-05-19 17:09:57

标签: iphone core-animation transition

我想将CATransition添加到我使用UIViewControllers显示的NSTimer

-(void)playAction:(id)sender
{
[audioPlayer play];
[self performSelector:@selector(displayviewsAction:) withObject:nil afterDelay:11.0];
}

- (void)displayviewsAction:(id)sender
{  
 First *firstController = [[First alloc] init];
 firstController.view.frame = CGRectMake(0, 0, 320, 480);
 [self.view addSubview:firstController.view];
 [self.view addSubview:toolbar];
 [firstController release];   
 self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Second) userInfo:nil repeats:NO];     
 }

-(void)Second 
{
Second *secondController = [[Second alloc] init];
secondController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:secondController.view]; 
[self.view addSubview:toolbar];
[secondController release];
self.timer = [NSTimer scheduledTimerWithTimeInterval:27 target:self selector:@selector(Third) userInfo:nil repeats:NO];
}

如果CATransition从第一个变为第二个等UIViewControllers,我将如何添加{{1}},等等。

提前感谢所有想法。

1 个答案:

答案 0 :(得分:3)

使用此 -

-(void)Second {
    Second *secondController = [[Second alloc] init];
    secondController.view.frame = CGRectMake(0, 0, 320, 480);

    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:kCATransitionReveal];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionReveal];

    [self.view addSubview:secondController.view];
    [self.view addSubview:toolbar];
    [secondController release];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:27 target:self selector:@selector(Third) userInfo:nil repeats:NO];
}

//您可以在此定义自己的CATransition动画类型。