繁体   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