Adding logo for iPhone app
I want to add a logo view as iPhone application lunch. I code as follows
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
UIImage image = [[UIImage alloc] imageWithContentsOfFile:@"1.jpg"];
UIImageView view = [[UIImageView alloc] initWithImage:image];
[window addSubViews:view];
[NSThread sleepForIntervalTime:10];
[view removeFromSubview];
[window addSubview: navigationController.view];
[window makeKeyAndVisible];
}
But simulator can't d开发者_StackOverflowisplay as I want.just display navigationController's view. I think the reason is iPhone render the first view after "applicationDidFinishLaunching" Are there other solutions about that?
Just add the image you want to be the LOGO to your project with the name: Default.png
It will automatically become the startup screen for your application.
Your approach won't work. applicationDidFinishLaunching
delegate runs after all the loading was done. Besides, delaying it for 10 seconds won't be accurate since application might load faster on some devices than others.
Pablo is right - you can just use the Default.png for this.
However, your code will never work for two reasons.
1)
The main thread of the application is the UI thread - the one responsible for dealing with updating the interface and this is the thread that is running your applicationDidFinishLaunching:
.
If you just call [NSThread sleepForIntervalTime:10]
the thread will sleep. However, this also means that while the thread is sleeping, the UI won't get updated. Then, when you call [view removeFromSuperview]
it will remove the image and carry on. You will never get to see the image!
To get your code to work you should do something like this :
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window addSubview: navigationController.view];
UIImage *image = [UIImage imageWithContentsOfFile:@"1.jpg"];
UIImageView *view = [[UIImageView alloc] initWithImage:image];
[window addSubView:view];
[view release];
[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(removeImage:) userInfo:view repeats:NO];
[window makeKeyAndVisible];
}
- (void) removeImage:(NSTimer *)timer {
UIImageView *view = (UIImageView *)timer.userInfo;
[view removeFromSuperview];
}
This code will show an image for 10 seconds and then remove it. However, if you just want an image at launch, using Default.png is definately the way to do it!
2)
You have added the navigator view infront of your image - in the code above, I have moved adding the navigator's view to be before the UIImage. This means that the image will be infront of the navigator for the 10 second delay until it is removed, revealing the navigator view.
Hope this helps,
Sam
精彩评论