应用程序启动后iOS 8启动图像

时间:2014-10-28 21:34:55

标签: ios webview ios8 splash-screen

首先让我说,我所知道的内容是苹果不赞同的,如果提交,将被App Store拒绝。这不是问题,因为无论如何都不会提交。这是一个内部应用程序。

现在就开始了。我需要一些帮助来设置if,else和else if语句。在迁移到iPhone 6和6+之前,我的当前代码适用于iPhone5 / 5s和低于屏幕尺寸的加载并在应用程序启动后发送正确的图像。

我的目标是将iPhone 6/6 +纳入此等式。

以下是与此相关的相关代码。

这会将图像加载到适当的屏幕尺寸。

    //Setting Splash Images
#define IS_IPHONE (!IS_IPAD)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone)

    bool isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));
    if (isiPhone5) {

        // Load iPhone 5 Splash
        UIImage *splash4Inch = [UIImage imageNamed:@"Default-568h@2x.png"];
        self.splash4InchPortrait = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 568.0f)];
        [self.splash4InchPortrait setImage:splash4Inch];
        [self.view addSubview:self.splash4InchPortrait];
        [self.view bringSubviewToFront:self.splash4InchPortrait];
        self.splash4InchPortrait.contentMode = UIViewContentModeScaleToFill;
    }

    else if (IS_IPAD) {
        // Load IPad Splash
        UIImage *splashPad = [UIImage imageNamed:@"Default-Portrait~ipad.png"];
        self.splashPadPortrait = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 768.0f, 1024.0f)];
        [self.splashPadPortrait setImage:splashPad];
        [self.view addSubview:self.splashPadPortrait];
        [self.view bringSubviewToFront:self.splashPadPortrait];
        self.splashPadPortrait.contentMode = UIViewContentModeScaleToFill;
    }

    else {
        // Load the iPhone 3.5" Splash
        UIImage *splash35Inch = [UIImage imageNamed:@"Default.png"];
        self.splash35InchPortrait = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
        [self.splash35InchPortrait setImage:splash35Inch];
        [self.view addSubview:self.splash35InchPortrait];
        [self.view bringSubviewToFront:self.splash35InchPortrait];
        self.splash35InchPortrait.contentMode = UIViewContentModeScaleToFill;
    }

根据加载的屏幕尺寸隐藏/取消隐藏所述图像。

//Get screen size
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (UIDeviceOrientationIsPortrait(self.interfaceOrientation)){
    //DO Portrait
    if (screenBounds.size.height <=480) {
        //code for 3.5-inch screen
        splash35InchPortrait.hidden = NO;
        splashRetina35InchPortrait.hidden = YES;
        splash4InchPortrait.hidden = YES;

    }else{
        // code for 3.5 Retina inch screen
        splashRetina35InchPortrait.hidden = NO;
    }

}else{
    // code for 4-inch screen
    splash35InchPortrait.hidden = YES;
    splashRetina35InchPortrait.hidden = YES;
    splash4InchPortrait.hidden = NO;

}

这是完成代码,因为图像渐渐淡出。

- (void)webViewDidFinishLoad:(UIWebView *)webview {

#define IS_IPHONE (!IS_IPAD)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone)

    bool isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));
    if (isiPhone5) {
        // Loading iPhone 5
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        NSLog(@"didFinish: %@; stillLoading:%@", [[webView request]URL],
              (webView.loading?@"NO":@"YES"));
    }
    else if (IS_IPAD) {
        // Loading IPAD
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        NSLog(@"didFinish: %@; stillLoading:%@", [[webView request]URL],
              (webView.loading?@"NO":@"YES"));
    }
    else {
        // Loading iPhone 3.5"
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        NSLog(@"didFinish: %@; stillLoading:%@", [[webView request]URL],
              (webView.loading?@"NO":@"YES"));
    }

}

正如你所看到的,我尽我所能地努力工作。我需要添加6/6 +代码。

或者,如果有人知道这样做的更简单的方法,那我就是全部。

主要目标是在应用加载后防止白色闪烁。我试过推迟启动,但由于我的应用程序主要是webview,它根本没有帮助。

感谢阅读和帮助。

1 个答案:

答案 0 :(得分:0)

好的,回过头来看看。我拥有我想要的一切。延迟消失,添加所有图像,甚至设法删除调用这些图像的专用视图控制器。没有笔尖,笔记本或故事板。

我的应用程序现在如何设置。我有一个左侧抽屉,如果我按下一个单元格,它会加载该视图但是再次调用闪屏。不理想。但现在它很完美。

这就是我的所作所为。

在我的AppDelegate中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//Removing splash screen user default on app launch 
    [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"Splash"];

    [self.window setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];
    [self.window setBackgroundColor:[UIColor clearColor]];
    [self.window makeKeyAndVisible];

    return YES;
}

查看控制器:

 - (void)viewDidLoad {
        [super viewDidLoad];
        //Splash Screen View Controller defaults
        if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"Splash"]]) {
            [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"Splash"];
            [[NSUserDefaults standardUserDefaults] synchronize];

            self.splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
            [self.view setCenter:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2)];
            [(UIImageView*)splashView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
            [self.splashView setContentMode:UIViewContentModeScaleToFill];
            [self.splashView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];
            [self.splashView setBackgroundColor:[UIColor clearColor]];
            [self.view addSubview:splashView];        
        }

    - (void)webView:(WKWebView *)webView didFinishNavigation: (WKNavigation *)navigation {
        //Check here if still webview is loding the content
        if (self.webView.isLoading){
            [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
        }

        else {
    //Splash Screen timer
            timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/1.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];
        }
    }

    - (void) viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        [self.webView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(didChangeOrientation:)
                                                     name:UIDeviceOrientationDidChangeNotification
                                                   object:nil];

        [self supportedInterfaceOrientations];
    }

    -(BOOL)shouldAutorotate {
        return YES;
    }

    - (void)didChangeOrientation:(NSNotification *)notification{
        [self setUpViewForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
    }

    -(void)setUpViewForOrientation:(UIInterfaceOrientation)orientation {
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

        //
        //Splash Screen Setup
        //
        CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
        CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
        if( screenHeight < screenWidth ){
            screenHeight = screenWidth;
        }

        if (UIInterfaceOrientationIsLandscape(orientation)) {
            if (IS_IPHONE) {

                if (screenWidth == 480){
                    // iPhone 4/4s, 3.5 inch screen
                    UIImage *iPhone4 = [UIImage imageNamed:@"LaunchImage-700-Landscape@2x.png"];
                    [self.splashView setImage:iPhone4];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPhone 4/4s");
                }
                if (screenWidth == 568){
                    // iPhone 5/5s, 4.0 inch screen
                    UIImage *iPhone5 = [UIImage imageNamed:@"LaunchImage-700-Landscape-568h@2x.png"];
                    [self.splashView setImage:iPhone5];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPhone 5/5s");
                }
                if (screenWidth == 667){
                    // iPhone 6, 4.7 inch screen
                    UIImage *iPhone6 = [UIImage imageNamed:@"LaunchImage-800-Landscape-667h@2x.png"];
                    [self.splashView setImage:iPhone6];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPhone 6");
                }
                if (screenWidth == 736){
                    // iPhone 6+, 5.5 inch screen
                    UIImage *iPhone6Plus = [UIImage imageNamed:@"LaunchImage-800-Landscape-736h@3x.png"];
                    [self.splashView setImage:iPhone6Plus];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPhone 6 Plus");
                }
            }

            else if (IS_IPAD) {
                if ([UIScreen mainScreen].scale == 1){
                    // iPad 2
                    UIImage *iPad = [UIImage imageNamed:@"LaunchImage-700-Landscape~ipad.png"];
                    [self.splashView setImage:iPad];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPad");
                }
                if ([UIScreen mainScreen].scale == 2) {
                    UIImage *iPad = [UIImage imageNamed:@"LaunchImage-700-Landscape@2x~ipad.png"];
                    [self.splashView setImage:iPad];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPad");
                }

            }
        }
        else {
            if (IS_IPHONE) {

                if (screenHeight == 480){
                    // iPhone 4/4s, 3.5 inch screen
                    UIImage *iPhone4 = [UIImage imageNamed:@"LaunchImage-700@2x.png"];
                    [self.splashView setImage:iPhone4];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPhone 4/4s");
                }
                if (screenHeight == 568){
                    // iPhone 5/5s, 4.0 inch screen
                    UIImage *iPhone5 = [UIImage imageNamed:@"LaunchImage-700-568h@2x.png"];
                    [self.splashView setImage:iPhone5];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPhone 5/5s");
                }
                if (screenHeight == 667){
                    // iPhone 6, 4.7 inch screen
                    UIImage *iPhone6 = [UIImage imageNamed:@"LaunchImage-800-667h@2x.png"];
                    [self.splashView setImage:iPhone6];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPhone 6");
                }
                if (screenHeight == 736){
                    // iPhone 6+, 5.5 inch screen
                    UIImage *iPhone6Plus = [UIImage imageNamed:@"LaunchImage-800-Portrait-736h@3x.png"];
                    [self.splashView setImage:iPhone6Plus];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPhone 6 Plus");
                }
            }

            else if (IS_IPAD) {
                if ([UIScreen mainScreen].scale == 1){
                    // iPad
                    UIImage *iPad = [UIImage imageNamed:@"LaunchImage-700-Portrait~ipad.png"];
                    [self.splashView setImage:iPad];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPad");
                }
                if ([UIScreen mainScreen].scale == 2){
                    UIImage *iPad = [UIImage imageNamed:@"LaunchImage-700-Portrait@2x~ipad.png"];
                    [self.splashView setImage:iPad];
                    [self.view addSubview:self.splashView];
                    //NSLog(@"iPad");

                }
            }
        }
    }

    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [self setUpViewForOrientation:toInterfaceOrientation];
    }

    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [self setUpViewForOrientation:toInterfaceOrientation];
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }

    //Image animation
    - (void)tick {
        if (!webView.loading) {
            [self performSelector:@selector(fadeimage) withObject:nil afterDelay:0.0];
        }
    }
    -(void)fadeimage{
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.3];
        [self.splashView setAlpha:0.0];
        [self.webView setAlpha:1.0];
        [UIView commitAnimations];

        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

        [self.webView setUserInteractionEnabled:YES];
        [self.view setUserInteractionEnabled:YES];
    }

非常确定这一切。希望这有助于某人面临类似的问题。