iPhone5来了,如何移植之前的原生应用和cocos2d游戏(转)

(原文:http://blog.sina.com.cn/s/blog_4b55f68601018j0h.html)

iPhone5来了,屏幕大小是4寸,来了不大不小的麻

下面分两种型来看,一种是使用Cocoa Touch的原生用,一种是使用Cocos2D引擎开的游 

1.原生

原生用的移植相较简单,一般只需按照以下步就可以搞定了: 

(1)安装Xcode4.5GM

(2)提供一个名Default-568h@2x.png的加载图(1136*640),注意这个命名规范只适用于加载图。

(3)如果auto resizing masks设置恰当,则基本上没有影响

(4)如果不是,则需要设置auto resizing masks

view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

5)使用iOS6所特有的Auto Layout(但应用就只适用于iOS6)

关于自动布局请参考教程:

http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2

6)关于自动旋转:UIViewController原有的shouldAutorotateToInterfaceOrientation:方法被弃用。因此需要使用supportedInterfaceOrientationsForWindow:

shouldAutorotate方法。

- (BOOL)shouldAutorotate {

    return YES;

}

- (NSUInteger)supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskAllButUpsideDown;    

}

7)如果对界面布局有较高的要求,则根据不同设备类型提供不同的图片

可以通过以下方式来判断:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

{

    CGSize result = [[UIScreen mainScreen] bounds].size;

    if(result.height == 480)

    {

        // iPhone Classic

    }

    if(result.height == 568)

    {

        // iPhone 5

    }

}

2.Cocos2D开发的游戏

 

对于游戏应用来说,自动布局的作用不大,需要提供两种分辨率的图片。

首先当然是要下载Xcode4.5 GM和最新的Cocos2d v2.1 beta了。

 

此外需要对设备类型进行判断,以便根据分辨率不同使用不同的图片

有两种方法:

1)根据屏幕大小来判断设备类型,也就是如果判断设备的高为1136,则为4寸设备。

方法同上。

 

2)使用第三方的类,这里要介绍下一个UIDeviceHardware的类,下载地址:(https://gist.github.com/1323251 

使用方法(举例):

  UIDeviceHardware *h = [[UIDeviceHardware alloc]init];

    NSString *platformType = [h platformString];

  [h release];   

     CCLabelTTF *device = [CCLabelTTF labelWithString:platformType fontName:@"Marker Felt"fontSize:64];

    device.position = ccp(size.width/2,size.height*0.7);

    [selfaddChild:device];

需要注意的是,由于手边没有iphone5touch 6,用4s测的时候,如果把代码换成[h platform],会显示iPhone4,1,因此推测iPhone5会显示iPhone5,1

便介UIDevice个苹果官方提供的类,非常有用

使用似下面的代

NSString *deviceType = [UIDevice currentDevice].model;

可以获取设备的类型,如iPhone,iPod touch等等。

还可以获取其它属性:

name  设备的名称,比如”My iPhone”

systemName  系统类型,如”iOS”

systemVersion, 固件版本,如”4.0”

uniqueIdentifier,设备标识符,可惜要被弃用

identifierForVendor,iOS6新增的NSUUID类型,设备唯一标识符,需要注意的是,同一开发商的不同应用享用相同的标识符。

UIDeviceBatteryState电池状态

isMultitaskingSupported,是否支持多任务

 

参考文章:

http://stackoverflow.com/questions/12396545/how-to-deal-with-iphone-5-screen-size

posted @ 2013-05-02 10:15  bxddno1  阅读(187)  评论(0)    收藏  举报