1

总的来说,我对 Objective-C 和 iOS 开发相对较新,如果我的问题有任何帮助和指导,我将不胜感激。

我已经编写了我的第一个应用程序,它是一个带有主视图和翻转视图的“实用程序”应用程序。该应用程序在模拟器和我的 iPhone 上都按预期工作。但是,从 Default.png 图像到我的主视图有一个明显而突然的变化。

我遵循了来自https://stackoverflow.com/a/9918650/1324822的 n13 建议代码,但是,我得到的只是主视图,然后是淡入黑色。

我在 AppDelegate.m 文件中的代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// set up your root view and stuff....
//.....(do whatever else you need to do)...

// show the main window, overlay with splash screen + alpha dissolve...
UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
[self.window addSubview:splashScreen];        
[self.window makeKeyAndVisible];

[UIView animateWithDuration:0.3 animations:^{splashScreen.alpha = 0.0;}
                 completion:(void (^)(BOOL)) ^{
                     [splashScreen removeFromSuperview];
                 }
 ];
return YES;
 }

我承认我正在“尝试”我项目的这一部分,尽管我非常想了解导致问题的原因以及如何解决它。我希望我需要在上面的某个地方指定我的 mainView,也许按照评论对其进行初始化,但我不确定如何做到这一点,因为没有过渡,唯一的要求是设置return YES;.

如果有帮助,这是一个故事板项目。我正在运行 Xcode 4.3.3。

再次感谢。

4

1 回答 1

2

这就是我做启动画面的方式:

我没有将其放入 App Delegate 中,而是放在查看的第一个屏幕上。你只需要在你的 rootViewController 中有两个实例变量,第一个是 UIView *black,第二个是 UIImageView *splash。然后 :

-(void) viewWillAppear:(BOOL)animated {

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{

    self.view.userInteractionEnabled = NO;
    black = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    black.backgroundColor = [UIColor blackColor];


    splash = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [splash addSubview:indicator];
    indicator.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2, 455);

    [indicator startAnimating];
    //the indicator part is arbitrary, of course

    splash.image = [UIImage imageNamed:@"Default.png"];

    [self.view addSubview:black];
    [self.view addSubview:splash];

});


}

然后:

-(void) viewDidAppear:(BOOL)animated {

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{



    [UIView animateWithDuration:0.4 delay:2 options:UIViewAnimationCurveEaseInOut animations:^{
        splash.alpha=0;
    } completion:^(BOOL finished) {
        [splash removeFromSuperview];

        [UIView animateWithDuration:0.45 delay:0.2 options:UIViewAnimationCurveEaseInOut animations:^{
            black.alpha = 0; 
        } completion:^(BOOL finished) {
            [black removeFromSuperview];
            black = nil;
            splash = nil;
            self.view.userInteractionEnabled = YES;

        }];
    }];

});


}

我没有使用具有导航控制器或选项卡视图控制器的应用程序测试此代码,但它的工作原理与常规视图控制器的魅力一样。

于 2012-06-28T18:16:32.673 回答