0

我知道是否有一个名为 Default.png 的文件,它会自动显示图像。但是,我想在它显示期间更改图像。仅供参考,我有 2 张图片 Default.png 和 default2.png。我想在显示 Default.png 之后显示 default2.png。我尝试了遵循的代码,但没有奏效。我需要做什么?

-(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];
}
4

3 回答 3

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];
}

编辑:

示例项目的链接: iphone 中的两个启动画面显示

于 2012-07-24T09:32:39.170 回答
0

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

调用的第一个 View Controller 应该实现viewWillAppear,因为它类似于在默认图像隐藏之前调用的最后一个方法。一切都已加载,您可以立即将子视图添加到主窗口。

我会用 2 种不同的方法来做,比如showOverrideDefaultImagehideOverrideDefaultImage。在 show 方法中,您将自己的视图添加到 appDelegate 窗口并触发

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

在 hide 方法中,只需从 superview 中删除您的视图。因此,您必须有一个指向该对象的有效指针。

就是这样。不要使用 NSThread。

于 2012-07-24T09:31:17.717 回答
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];
}
于 2012-07-24T09:41:20.030 回答