• 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吧。

  • 相关阅读:
    Vue核心之数据劫持
    Flex 布局教程
    Grid布局
    我们都在深夜,参差不齐地入眠
    一个十分好用的动画工具:Velocity.js
    前端知识点总结——jQuery(下)
    前端知识点总结——jQuery(上)
    虫师Selenium2+Python_2、测试环境搭建
    虫师Selenium2+Python_11、自动化测试项目实战
    虫师Selenium2+Python_12、BDD框架之Lettuce入门
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/2458478.html
Copyright © 2020-2023  润新知