簡體   English   中英

應用啟動后的iOS 8啟動畫面

[英]iOS 8 Splash images after app launch

首先,我要說的是,我所知道的被Apple拒之門外,如果提交,將會被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,因此完全沒有幫助。

感謝您的閱讀和幫助。

好的,所以轉回這個。 我擁有我想要的一切。 延遲消失了,添加了所有圖像,甚至設法刪除了調用這些圖像的專用視圖控制器。 沒有筆尖,小臂或情節提要。

現在如何設置我的應用程序。 我有一個左側抽屜,如果我碰到一個單元格,它將加載該視圖,但再次調用啟動屏幕。 不理想。 但是現在很完美。

這就是我所做的。

在我的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];
    }

可以肯定的就是一切。 希望這可以幫助面臨類似問題的人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM