zoukankan      html  css  js  c++  java
  • iPhone开发:利用controller使cocos2d自动支持180度旋转

    iPad程序有一条不成文的规定:所有app必须支持屏幕旋转,至少支持180度旋转,仅仅支持一个方向的app将被无情拒绝。

    目前cocos2d已经支持iPad开发,却并不支持屏幕旋转。

    下面我们就利用UIController的自动旋转特性,让cocos2d支持180度旋转:

    1。创建controller,且叫做TransController吧,内容如下

    #import <UIKit/UIKit.h>

    #define LANDSCAPE_MODE YES

    @interface TransController : UIViewController {

    }

    @end

    #import "TransController.h"

    @implementation TransController

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

        // Overriden to allow any orientation.

    if (LANDSCAPE_MODE){

    if (interfaceOrientation == UIDeviceOrientationLandscapeLeft||interfaceOrientation == UIDeviceOrientationLandscapeRight) {

    return YES;

    }

    }else {

    if (interfaceOrientation == UIDeviceOrientationPortrait||interfaceOrientation == UIDeviceOrientationPortraitUpsideDown) {

    return YES;

    }

    }

    return NO;

    }

    - (void)didReceiveMemoryWarning {

        // Releases the view if it doesn't have a superview.

        [super didReceiveMemoryWarning];

        // Release any cached data, images, etc that aren't in use.

    }

    - (void)viewDidUnload {

        [super viewDidUnload];

        // Release any retained subviews of the main view.

        // e.g. self.myOutlet = nil;

    }

    - (void)dealloc {

        [super dealloc];

    }

    @end

    #define LANDSCAPE_MODE YES 用来设定app的横竖屏模式

    2。修改appdelegate

    无论程序是横/竖,setDeviceOrientation都为竖屏,方向总是相对的,呵呵,即总是:

    [[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationPortrait];

    TransController *tc = [[TransController alloc] init];

    tc.view.frame = window.frame;

    [window addSubview:tc.view];

    [[CCDirector sharedDirector] attachInView:tc.view];

    tc无需释放(因为没有意义),也不可以释放(释放后将不能旋转),如果你喜欢释放的话,就在.h中定义然后dealloc中去release吧。

  • 相关阅读:
    (转)AS3中实现卡马克卷轴算法
    (转)flash位图缓存cacheAsBitmap
    (转)addFrameScript函数的纠结
    (转)flash安全策略文件
    (转)脏矩形技术学习
    (转)stopImmediatePropagation 和stopPropagation的区别
    (转)flash对象池技术
    揭开嵌入式C面试题背后的玄机
    一次遍历找链表倒数第n个节点
    N!的尾部连续0的个数
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/2458478.html
Copyright © 2011-2022 走看看