2012-07-24 23 views
0

我知道是否有一个名为Default.png的文件会自动显示图像。 但是,我想在展示过程中更改图片。仅供参考,我有2张图片Default.png和default2.png。 我想在show Default.png后显示default2.png。 我尝试了下面的代码,但没有奏效。 我需要做什么?如何在应用程序启动时显示2个介绍视图?

-(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 

//.................................................................. 
//self.window bullabulla~ 

[self performSelectorOnMainThread:@selector(showIntro2View) withObject:nil waitUntilDone:YES]; 
//[self showIntro2View]; //also tried this, but not work. 

[self.window addsubview:tabbarController]; 
[self.window makeKeyAndVisible]; 
} 
-(void) showIntro2View { 
UIImageView *intro2 = [[UIImageView alloc]initwithframe:cgrectmake(0,0,320,460)]; 
intro2.image = [UIImage imagenamed:@"default2.png"]; 
[self.window addSubview:intro2]; 
[self.window bringSubviewToFront:intro2]; 
[NSThread sleepfortimeinterval:2]; 
} 
+0

为什么使用performSelectorOnMainThread? ?你已经在主线程中! ,你能告诉我们这个代码的结果是什么吗? – ahmad 2012-07-24 09:20:57

+0

只显示主视图。我也试过[self showIntro2View],而不是MainThread与sleepcode,但它是一样的。 – user1471568 2012-07-24 09:39:52

回答

1

在您的APP DELEGATE。 这样的事情应该做的工作:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    UIImageView *imageView = [[[UIImageView alloc] initWithFrame:self.window.bounds] autorelease]; 
    UIImage *image = [UIImage imageNamed:@"NAMEOFYOURSPLASHSCREEN.png"]; 
    imageView.image = image; 
    [self.window addSubview:imageView]; 
    [self.window makeKeyAndVisible]; 
    [self performSelector:@selector(remove1stSplash:) withObject:imageView afterDelay:5]; 
    return YES; 
} 

- (void)remove1stSplash:(UIImageView *)1stView { 
    UIImageView *imageView = ... 
    [self.window addSubview:imageView]; 
    [self performSelector:@selector(remove2ndSplash:) withObject:imageView afterDelay:5]; 
    [1stView removeFromSuperView]; 
} 

- (void)remove2ndSplash:(UIImageView *)2ndView { 
    [self.window addSubview:..... 
    [2ndView removeFromSuperView]; 
} 

编辑:

链接的示例项目: Two Splash Screen display in iphone

+0

在此先感谢〜! – user1471568 2012-07-24 10:08:10

0

正如您可能知道的那样,您对Default img的显示时间没有实际影响。但你知道什么时候显示和隐藏。它仅显示当应用程序第一次运行时,该应用程序不在后台或在不使用它的一段时间后终止。

被调用的第一个视图控制器应实现viewWillAppear,因为它类似于默认图像隐藏之前调用的最后一个方法。有一切都被加载,你可以立即添加一个子视图到主窗口。

我会用两种不同的方法来做,如showOverrideDefaultImagehideOverrideDefaultImage。在演出方法添加您自己查看到的appDelegate窗口和火

[self performSelector:@selector(hideOverrideDefaultImage) withObject:nil afterDelay:2]; 

在隐藏方法简单地移除上海华你的看法。因此你必须有一个指向这个对象的有效指针。

就是这样。不要使用NSThread。

+0

当我在viewWillAppear中实现时出现问题,我使用tabbarController和navigationController,在tabbar和导航栏中显示介绍图像。 – user1471568 2012-07-24 09:41:15

+0

是的,你应该在应用程序委托窗口中显示图像,如下所示:'[[[[UIApplication sharedApplication] delegate] window] addSubview:yourSubview];'将其粘贴到视图控制器的show方法中。这应该超出所有其他观点。 – Fab1n 2012-07-24 12:03:51

0

这样做:

-(void) showIntro2View 
{ 
    UIImageView *intro2 = [[UIImageView alloc]initwithframe:cgrectmake(0,0,320,460)]; 
    intro2.image = [UIImage imagenamed:@"default2.png"]; 
    intro2.animationImages = [NSArray arrayWithObjects:  
          [UIImage imageNamed:@"Default.png"], 
          [UIImage imageNamed:@"default2.png"], nil]; 
    intro2.animationDuration = 2.0f; 
    intro2.animationRepeatCount = 0; 
    [intro2 startAnimating]; 

    [self.window addSubview:intro2]; 
    [self.window bringSubviewToFront:intro2]; 
    [NSThread sleepfortimeinterval:2]; 
} 
+0

谢谢〜!我下次会尝试这个。 – user1471568 2012-07-24 10:08:41

相关问题