zoukankan      html  css  js  c++  java
  • Cocos2d中从场景切换到UIViewController视图方法总结

     第一种:直接从场景切换到UIViewController视图(网上流传的版本)
    - (void) showUIViewController:(UIViewController *) controller
    {
     

       [[Director sharedDirector] pause];
        
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:.5];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:[[Director sharedDirector] openGLView] cache:YES];
        
        [[[Director sharedDirector] openGLView] addSubview:controller.view];
        
        [UIView commitAnimations];
    }

    从UIViewController视图切换到场景
    //返回场景视图
    - (void) hideUIViewController:(UIViewController *) controller
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:.5];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animDone:finished:context:)];
        
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:[[Director sharedDirector] openGLView] cache:YES];
        
        [controller.view removeFromSuperview];
        
        [UIView commitAnimations];
    }

    -(void)animDone:(NSString*) animationID finished:(BOOL) finished context:(void*) context
    {    
        [[Director sharedDirector] resume];
    }
     
    备注一点:
    代码1:[[[[CCDirector sharedDirector] openGLView] window]addSubview:viewController.view];
    效果:添加的view会随着window是横屏还是竖屏变化,添加之后如果view下面覆盖了一个cocos2d的按钮,点击按钮的区域按钮不响应点击。
    代码2:[[[CCDirector sharedDirector] openGLView]addSubview:viewController.view];
    效果:不随着变化,并且底部的按钮相应点击
     
    第二种:通过RootViewController切换 (自己写的)
     
    1、默认情况下面,cocos2d 模板并没有在AppDelegate里面包含一个RootViewController的属性,因此必须手动添加一个。
    跳转到AppDelegate.h文件,并添加下面的代码:
    @property (nonatomic, retain) RootViewController *viewController;

    然后跳转到AppDelegate.m,synthesize之:

    @synthesize viewController;

    2、添加

    #import "AppDelegate.h"

    - (void) showUIViewController:(UIViewController *) controller
    {
        AppDelegate *delegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
        [delegate.viewController presentModalViewController:controller animated:YES];
       
    }

    从UIViewController视图切换到场景
    //返回场景视图

    第一种:在UIViewController调用dismissModalViewControllerAnimated 来返回,例如:

    [self dismissModalViewControllerAnimated:YES];

    第二种使用委托,让RootViewController来控制,例如

    [appdelegate.viewController dismissModalViewControllerAnimated:YES];
  • 相关阅读:
    halcon算子翻译——dev_set_paint
    Halcon算子翻译——dev_set_lut
    JDK、JRE、JVM各自是什么、以及什么关系
    dict 增删改查
    str 操作方法
    python基础_格式化输出(%用法和format用法)
    python spilt()函数的使用方法
    iterable- 什么是可迭代对象
    list 增 删 改 查 及 公共方法
    python 基本数据类型
  • 原文地址:https://www.cnblogs.com/gaoxiao228/p/2526284.html
Copyright © 2011-2022 走看看