xcode 4.5如何在发布时选择故事板
试图使我的应用程序同时适用于iPhone 5和iPhone 4/4s。我尝试了“自动布局”,但似乎对我的应用程序不起作用。我还读到iOS 5不支持它。AutoLayout在具有UIScrollview和在代码中重新调整大小的UIPicker的视图控制器上特别失败。拥有两个故事板,一个是4英寸,一个是3.5英寸,这似乎是一个不错的选择 两个故事板似乎是我的解决方案。这给我留下了两个问题xcode 4.5如何在发布时选择故事板,xcode,storyboard,uistoryboard,xcode4.5,Xcode,Storyboard,Uistoryboard,Xcode4.5,试图使我的应用程序同时适用于iPhone 5和iPhone 4/4s。我尝试了“自动布局”,但似乎对我的应用程序不起作用。我还读到iOS 5不支持它。AutoLayout在具有UIScrollview和在代码中重新调整大小的UIPicker的视图控制器上特别失败。拥有两个故事板,一个是4英寸,一个是3.5英寸,这似乎是一个不错的选择 两个故事板似乎是我的解决方案。这给我留下了两个问题 如果是4/4s/5 go,代码应该在哪里检测?我会在appDelegate.m中假设didfishlaunchi
目前唯一的方法是检查您是否正在使用iPhone 5是
[UIScreen mainScreen]界限]
和[[UIScreen mainScreen]比例]
BOOL isIphone5 = (([[UIDevice currentDevice] userInterfaceIdiom]
== UIUserInterfaceIdiomPhone) && (([UIScreen mainScreen].bounds.size.height *
[[UIScreen mainScreen] scale]) >= 1136));
仅当您至少添加了默认值时,此选项才有效-568h@2x.png
将映像启动到应用程序。否则它将始终返回false。(因为如果您没有启动图像,屏幕将显示字母框)
要将情节提要设置为iPhone 5版本,您可能需要看一看这是一个很好的问题。
你需要做的是
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIStoryboard *storyBoard;
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 1136){
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_5" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
}
return YES;
}
如果有人不知道如何执行步骤1,请按以下步骤操作。
MainStoryboard.storyboard
,并将新的故事板重命名为MainStoryboard 5.storyboard
将文件添加到..
在完成以上所有操作后,您可能需要使用“产品>清洁”来实现此功能。我从fields.cage answer中获得了灵感,并将其改编为我的代码,效果很好。谢谢
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIStoryboard *storyBoard;
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 1136){
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone5" bundle:nil] autorelease];
}
else
{
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
}
}
我最近一直在做的是在我需要检查设备的任何类中添加define语句。这也可以在任何全局头文件中完成
#define IS_IPHONE (!IS_IPAD)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone)
布尔测试是从
如果您已经在使用情节提要,并且只想更改项目开始时针对iPhone 5设备的默认情节提要,则此功能非常有效。如果您是从零开始使用现有的非故事板项目,您可以这样做
#define IS_IPHONE (!IS_IPAD)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone)
bool isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));
if (isiPhone5) {
// Load iPhone 5 Storyboard
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
else if (IS_IPAD) {
// Load IPAD StoryBoard
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
else {
// Load the iPhone 3.5" storyboard
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
当我现在开始一个项目时,我在故事板中设计iPhone 3.5“版本(如果我使用的是故事板),然后当我完成设计后,我进入我的项目文件并找到故事板文件。由于故事板文件只是一个XML布局文件,我可以将该文件加载到我最喜欢的文本编辑器中并更改两个标记
将iPhone转换为iPad
targetRuntime=“iOS.CocoaTouch
”targetRuntime=“iOS.CocoaTouch.iPad”
这里重要的是,如果您只需将iPhone5添加到现有项目中,您只需进行第一次检查即可覆盖默认值,并加载特殊的情节提要文件。这让我不用在iPhone 5的代码中手动布局所有对象 第一个非常好的方法简单明了,但是如果你想集成乘法设备,请看这里:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIStoryboard *storyBoard;
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 1136){
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_5" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
}
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIStoryboard *storyBoard;
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 1136){
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_5" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
}
return YES;
}
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIStoryboard *storyBoard;
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width *scale, result.height *scale);
//----------------HERE WE SETUP FOR IPHONE4/4s/iPod----------------------
if(result.height == 960){
storyBoard = [UIStoryboard storyboardWithName:@"iPhone4_Storyboard" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
//----------------HERE WE SETUP FOR IPHONE3/3s/iPod----------------------
if(result.height == 480){
storyBoard = [UIStoryboard storyboardWithName:@"iPhone4_Storyboard" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
}
return YES;
}
就这样,现在我们有了一款适用于iPhone 3/3Gs/4/4s/5 iPod(AllGen)iPad 1/2/3/4 Mini和Retina的通用应用程序
谢谢你的家伙你也应该考虑使用Struts和Struts来调整你的视图,而不是复制你的故事板,特别是如果所有正在改变的是布局。它可以很容易地导致一个更可维护的解决方案,并支持iOS的先前版本。使用所提供的答案,我创建了一个类别,使之更容易。--非常简单…或者谢谢。在运行项目之前,请确保您已经添加了启动屏幕:)我最近开发了另一个应用程序,并在故事板中构建了所有4英寸显示屏。在t上运行时