cocos2d场景和UIViewController视图的切换

时间:2022-08-22 23:28:52

cocos2d中从场景切换到UIViewController视图
- (void) showUIViewController:(UIViewController *) controller
{
 

    [[DirectorsharedDirector] pause];
     
      [UIViewbeginAnimations:nil context:NULL];
      [UIViewsetAnimationDuration:.5];
      [UIViewsetAnimationTransition:UIViewAnimationTransitio nCurlUpforView:[[Director sharedDirector] openGLView] cache:YES];
     
      [[[DirectorsharedDirector] openGLView] addSubview:controller.view];
     
      [UIViewcommitAnimations];
}

cocos2d中从UIViewController视图切换到场景
//返回场景视图
- (void) hideUIViewController:(UIViewController *) controller
{
      [UIViewbeginAnimations:nil context:NULL];
      [UIViewsetAnimationDuration:.5];
      [UIViewsetAnimationDelegate:self];
      [UIViewsetAnimationDidStopSelec tor:@selector(animDone:finished:context:)];
     
      [UIViewsetAnimationTransition:UIViewAnimationTransitio nCurlDownforView:[[Director sharedDirector] openGLView] cache:YES];
     
      [controller.view removeFromSuperview];
     
      [UIViewcommitAnimations];
}

-(void)animDone:(NSString*) animationID finished:(BOOL) finishedcontext:(void*) context
   
      [[DirectorsharedDirector] resume];
}