开发者

Help required in converting iPhone App to iPad

I am using the latest Xcode and i created 开发者_运维问答a view based universal app and started building focusing on iPhone and now it is mandatory for me to put it in iPad. I didnt use the Interface builder in the development as more dynamic screen changes were expected from the beginning. In the code i have put all the screens with CGRECTMake(0,0,320,480).

Now when i tried to run the app in a iPad simulator, the app sticks to the top corners of the simulator with width as 320 and height as 480 and the rest of the screen looks white instead of coming up in the middle of the screen with a border and 2x options.

I have made the Main nib file base name (iPad) property in .plist file to my iPhone XIB name. I know this is one major reason why the app sticks to the top, but how to make this generic and make my app look proper in iPad?

Kindly help


If you create your views programatically you have to set everything that has a size twice, once for iPhone/iPod and once for iPad. You can do something like:

if ([Utils isIPad]) {
  rect = CGRectMake(0,0,640,1024);
}
else {
  rect = CGRectMake(0,0,320,480);      
}

[Utils isIPad] would be something like:

+ (BOOL)isIPad {
#ifdef UI_USER_INTERFACE_IDIOM
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#else
    return NO;
#endif
}

Doing this with nibs is easier and faster, though. You just have to use the correct nib in that case. Something like:

if ([Utils isIPad]) {
    login = [[LoginController alloc] initWithNibName:@"LoginController-iPad" bundle:nil];               
}
else {
    login = [[LoginController alloc] initWithNibName:@"LoginController" bundle:nil];
}


In response to dkk's answer, wouldn't it be more convenient to use the application frame of the main screen? This would return the correct frame size depending on the device without manual checks or hardcoded screen sizes.

[UIScreen mainScreen] applicationFrame]

More info: UIScreen Class Reference, refer to the applicationFrame property

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜