经过几个月的编码,我成功地完成了我的应用程序。现在我正在尝试将初始启动画面图像添加到我的应用程序中。我该如何进行?我有两张图片:一张是公司徽标,另一张是应用程序徽标(这些闪屏是为了隐藏加载时间)。我到处寻找可能的答案,但最终没有解决方案。当我命名单个图片Default-Landscape.png并运行 Ipad 应用程序时 - 图像一直显示,直到主视图控制器加载,但我希望第一个图像显示 1 秒钟并淡出到第二个图像,这将也会显示1 秒钟,然后出现主视图控制器(原始应用程序页面)。
我检查了各种答案,但似乎都没有工作-Xcode 4 和 iPad2 启动画面问题 为纵向和横向模式设置启动图像-iPad 等。
这是我的相同代码-AppDelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSArray *docDir=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath=[docDir objectAtIndex:0];
databasePath=[docPath stringByAppendingPathComponent:@"something.sqlite"];
//databasePath1=[docPath stringByAppendingPathComponent:@"something.sqlite"];
NSString *bundlePath=[[NSBundle mainBundle]pathForResource:@"something" ofType:@"sqlite"];
NSFileManager *mngr=[NSFileManager defaultManager];
if ([mngr fileExistsAtPath:databasePath]) {
NSLog(@"File Exists");
}
else
{
[mngr copyItemAtPath:bundlePath toPath:databasePath error:NULL];
NSLog(@"File Created");
}
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
我现在应该如何进行?我是否应该使用 uiImageView 创建一个像 (splashScreen 1 和 splashScreen 2) 这样的新类并更改didFinishLaunchingWithOptions方法?任何帮助将不胜感激。
更新日期:2013 年 5 月 30 日
Appdelegate.h
#import <UIKit/UIKit.h>
#import "sqlite3.h"
#import "FBInteract.h"
#import "splashScreen1.h"
sqlite3 *dbHandler;
NSString *databasePath;
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *naviObj;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) UINavigationController *naviObj;
@end
Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
splashScreen1 *splashScreen1PageObj=[[splashScreen1 alloc]init];
self.naviObj = [[UINavigationController alloc]initWithRootViewController:splashScreen1PageObj];
self.window.rootViewController = self.naviObj;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.window makeKeyAndVisible];
return YES;
}
splashScreen1.h和splashScreen2.h
#import <UIKit/UIKit.h>
#import "splashScreen2.h"
@interface splashScreen1 : UIViewController
{
IBOutlet UIImageView *imgObjSplashImage; // IBOutlet UIImageView *objSplashImage; - in splashScreen2.h
}
-(void)hideSplash;
-(void)navigationToMain;
-(void)showSplash;
@end
splashScreen1.m和splashScreen2.m
- (void)viewDidLoad
{
// Do any additional setup after loading the view from its nib.
[NSTimer scheduledTimerWithTimeInterval:1.2 target:self selector:@selector(showSplash) userInfo:nil repeats:NO];
self.navigationController.navigationBarHidden=YES;
[imgObjSplashImage setAlpha:0]; //objSplashImage instead of imgObjSplashImage in splashScreen2
[super viewDidLoad];
}
-(void)showSplash{
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:1.2];
[imgObjSplashImage setAlpha:1]; //objSplashImage instead of imgObjSplashImage in splashScreen2
[UIImageView commitAnimations];
[NSTimer scheduledTimerWithTimeInterval:2.4 target:self selector:@selector(hideSplash) userInfo:nil repeats:NO];
}
-(void)hideSplash{
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:1.4];
[imgObjSplashImage setAlpha:0]; //objSplashImage instead of imgObjSplashImage in splashScreen2
[UIImageView commitAnimations];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(navigationToMain) userInfo:nil repeats:NO];
}
#pragma mark
#pragma mark - Navigation Coding
-(void)navigationToMain {
//[self dismissModalViewControllerAnimated:YES];
[self dismissViewControllerAnimated:NO completion:Nil];
ViewController *ViewControllerPageObj=[[ViewController alloc]init];
[self.navigationController pushViewController:ViewControllerPageObj animated:NO];
[ViewControllerPageObj release];
//[self presentViewController:ViewControllerPageObj animated:NO completion:Nil];
}
-(void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBarHidden=YES;
}
问题是 ViewController(main ViewController) 没有加载...我在ViewController.m 的 viewDidLoad 部分收到错误消息“发送到已释放实例的消息”
RootViewController -> splashScreen1 -> splashScreen2 工作正常(所有动画淡入淡出)但最终的 ViewController 没有加载..