2012-06-01 27 views
1

我有一个通用的应用程序。在这个应用程序中,我将引言图像设置为启动画面。对于iPhone而言,我需要将不同的图像设置为启动画面,并为iPad设置不同的图像。当我使用下面的代码时,它适用于iphone,但不适用于ipad.here是我的代码。如何使用默认启动画面进行通用应用程序?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    [self copyDatabaseIfNeeded]; 
    [window addSubview:navigationController.view]; 
    [window makeKeyAndVisible]; 

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{ 
    splashViewBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)]; 
    splashViewBg.image = [UIImage imageNamed:@"jamil.png"]; 
    //splashViewBg.contentMode = UIViewContentModeScaleAspectFill; 
    [window addSubview:splashViewBg]; 

    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)]; 
    splashView.image = [UIImage imageNamed:@"jamil.png"]; 
    //splashView.contentMode = UIViewContentModeScaleAspectFill; 
    splashView.alpha = 0.0f; 
} 
else 
{ 
    splashViewBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    splashViewBg.image = [UIImage imageNamed:@"defualt.png"]; 
    //splashViewBg.contentMode = UIViewContentModeScaleAspectFill; 
    [window addSubview:splashViewBg]; 

    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    splashView.image = [UIImage imageNamed:@"defualt.png"]; 
    //splashView.contentMode = UIViewContentModeScaleAspectFill; 
    splashView.alpha = 0.0f; 
} 

[UIView beginAnimations:@"show" context:NULL]; 
[UIView setAnimationDuration:1.0f]; 
[UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
[UIView setAnimationDelegate:self]; 
splashView.alpha = 1.0f; 
[UIView commitAnimations]; 

[self performSelector:@selector(removeSplash) withObject:nil afterDelay:2.0]; 

[self performSelector:@selector(removeSplashBg) withObject:nil afterDelay:3.5]; 

return YES; 
} 

- (void) removeSplash { 
    [UIView beginAnimations:@"hide" context:NULL]; 
    [UIView setAnimationDuration:1.0f]; 
    [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
    [UIView setAnimationDelegate:self]; 
    splashView.alpha = 0.0f; 
    [UIView commitAnimations]; 
} 

    - (void) removeSplashBg { 
     [splashView removeFromSuperview]; 
     [splashViewBg removeFromSuperview]; 
} 
+0

您是否尝试过调试,无论条件是否正确?因为它总是会去别的地方。 – rishi

+0

@rishi是的我使用断点时,我使用ipad我的控制运行if部分。 – jamil

+0

图像是否存在,是否添加到您的项目中,名称是否正确?检查断点后,如果图像得到一个值。这是最可能的错误。 – jrturton

回答

2

我知道这并不直接回答你的问题,但苹果的指导方针明确说不使用启动画面图像。它非常不鼓励,并且可能会为您的用户创造非常差的,不一致的体验。如果您必须在应用程序加载时显示屏幕,则无需编写任何代码即可完成此操作。只需将图像命名为Default.png和[email protected]即可。它们将自动加载并显示为启动画面。请参阅documentation for "Launch Images"

相关问题