编辑1:将代码更改为:
delegate.h:
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
ViewController *viewController;
UIImageView *splashView;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet ViewController *viewController;
@property (nonatomic, retain) IBOutlet UIImageView *splashView;
- (void)removeSplash;
@end
delegate.m:
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
@synthesize window;
@synthesize viewController;
@synthesize splashView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Splash" ofType:@"png"]];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[window makeKeyAndVisible];
[self performSelector:@selector(removeSplash) withObject:nil afterDelay:5.0];
[window addSubview:viewController.view];
return YES;
}
- (void)removeSplash {
[splashView removeFromSuperview];
[splashView release];
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
编辑2:
当我使用:
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Splash" ofType:@"png"]];
if (splashView.image == nil) {
NSLog(@"splashView is nil");
}
它记录"splashView is nil“
我的Viewcontroller是空的,只是为了调试目的。
发布于 2010-10-26 16:41:39
正如你可能已经知道的,闪屏是不被鼓励的。既然你的图片是Default.png,它不是已经在应用程序启动时自动显示了吗?
在任何情况下,sleep()调用都可能阻塞UI。删除sleep()并将其后面的语句( removeFromSuperview等)移动到应用程序委托中的另一个方法。使用performSelector:withObject:afterDelay:
调用此方法。将performSelector调用放在当前有睡眠调用的位置。
此外,您应该使用didFinishLaunchingWithOptions方法,而不是旧的applicationDidFinishLaunching方法。
https://stackoverflow.com/questions/4025609
复制相似问题