1

经过几个月的编码,我成功地完成了我的应用程序。现在我正在尝试将初始启动画面图像添加到我的应用程序中。我该如何进行?我有两张图片:一张是公司徽标,另一张是应用程序徽标(这些闪屏是为了隐藏加载时间)。我到处寻找可能的答案,但最终没有解决方案。当我命名单个图片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.hsplashScreen2.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.msplashScreen2.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 没有加载..

4

1 回答 1

1

为此,您肯定需要另一个 VC,我们称之为 StartViewController。在那里添加一个 imageView、块旋转和 setTimer:

[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(moveOnAndChangeVC:) userInfo:nil repeats:NO];

如果您开发 NavigationControl 应用程序,您还应该更改 rootVC,例如:

+(void)replaceRootVCWithVC:(id)vc {
    NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[sharedAppDelegate navigationController] viewControllers]];
    if(![viewControllers isEmpty])
        [viewControllers replaceObjectAtIndex:0 withObject:vc];
    else
        [viewControllers addObject:vc];

    [[sharedAppDelegate navigationController] setViewControllers:viewControllers];
}

编辑:

您应该使用初始化程序更改您的 appDelegate 行:

self.viewController = [[[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil] autorelease];

这应该将您的 VC 称为 rootVC。

然后在 StartViewController.m 你应该识别设备(这是一个只有 iPad 的应用程序,对吗?不是通用的)和方向:

+(NSString*)recognizeDeviceAndOrientation {

    NSMutableString * returnString;
    if([StartViewController deviceInterfaceOrientation] == UIInterfaceOrientationLandscapeLeft ||    [StartViewController deviceInterfaceOrientation] == UIInterfaceOrientationLandscapeRight) {
        returnString = @"Default-Landscape";
    } else {
        returnString = @"Default-Portrait";
    }

    if([UIScreen mainScreen].scale == 2.0)
        return [NSString stringWithFormat:@"%@%@",returnString,@"@2x"];;
    else
        return returnString;
}

+(UIInterfaceOrientation)deviceInterfaceOrientation {
    return [[UIApplication sharedApplication] statusBarOrientation];
}

这将返回一个具有正确方向的 DefaultScreen 名称的字符串。如果您只处理一个方向,请忘记它。

然后在 viewDidLoad 中添加 imageView:

- (void)viewDidLoad {
    [super viewDidLoad];    
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:[StartViewController recognizeDeviceAndOrientation]] autorelease];
   [imageView setFrame:self.frame];
   [imageView setContentMode:UIViewContentModeScaleToFill];
   [self.view addSubview:imageView];

   [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(moveOnAndChangeVC:) userInfo:nil repeats:NO];
}

这将调用一个计时器并设置 imageView。

-(IBACtion)moveOnAndChangeVC:(id)sender {
   //if you using navigation app
   ViewController *vc = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
   [self.navigationController pushViewController:vc animated:NO];
}

这将起作用。然后,如果您想摆脱“后退按钮”,只需像我在开头所说的那样更改 rootView 控制器。在您的 ViewController 类中执行此操作。

于 2013-05-29T09:15:06.553 回答