0
EDIT 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是空的,僅用於調試目的。
雖然不鼓勵啓動屏幕,但如果您的應用程序需要一秒或兩秒以上的加載,我認爲確保它看起來不像可以與之交互的UI是很好的UI。您的用戶界面上的一個較小的警報閃屏看起來相當不錯。 – 2010-10-26 16:54:34
當我把它放在我的資源文件夾中時,Default.png不會自動工作。我們在說話時正在嘗試其他解決方案。 – lugte098 2010-10-26 20:27:10
同時將'[window addSubview:viewController.view];'移到'removeSplash'方法(使其成爲該方法的最後一行)。 – Anna 2010-10-26 20:43:47