获取APP的Launch Image

效果图:

首先我们来看看该方法,我们可以从中获取到很多我们需要操作的信息:

[NSBundle mainBundle] infoDictionary]

打印结果:

{
    BuildMachineOSBuild = 15E65;
    CFBundleDevelopmentRegion = en;
    CFBundleExecutable = "OC\U6d4b\U8bd5";
    CFBundleIcons =     {
        CFBundlePrimaryIcon =         {
            CFBundleIconFiles =             (
                AppIcon29x29,
                AppIcon40x40,
                AppIcon57x57,
                AppIcon60x60
            );
        };
    };
    CFBundleIdentifier = "HH.OC--";
    CFBundleInfoDictionaryVersion = "6.0";
    CFBundleInfoPlistURL = "Info.plist -- file:///Users/liuxianzhi/Library/Developer/CoreSimulator/Devices/D67FF738-795E-472C-97B5-3C6187AD9058/data/Containers/Bundle/Application/254DB231-BFCF-4D99-AEA0-737B63F20620/OC%E6%B5%8B%E8%AF%95.app/";
    CFBundleName = "OC\U6d4b\U8bd5";
    CFBundleNumericVersion = 16809984;
    CFBundlePackageType = APPL;
    CFBundleShortVersionString = "1.0";
    CFBundleSignature = "????";
    CFBundleSupportedPlatforms =     (
        iPhoneSimulator
    );
    CFBundleVersion = 1;
    DTCompiler = "com.apple.compilers.llvm.clang.1_0";
    DTPlatformBuild = "";
    DTPlatformName = iphonesimulator;
    DTPlatformVersion = "9.3";
    DTSDKBuild = 13E230;
    DTSDKName = "iphonesimulator9.3";
    DTXcode = 0730;
    DTXcodeBuild = 7D175;
    LSRequiresIPhoneOS = 1;
    MinimumOSVersion = "6.1";
    UIDeviceFamily =     (
        1
    );
    UILaunchImageFile = LaunchImage;
    UILaunchImages =     (
                {
            UILaunchImageMinimumOSVersion = "8.0";
            UILaunchImageName = "LaunchImage-800-Portrait-736h";
            UILaunchImageOrientation = Portrait;
            UILaunchImageSize = "{414, 736}";
        },
                {
            UILaunchImageMinimumOSVersion = "8.0";
            UILaunchImageName = "LaunchImage-800-667h";
            UILaunchImageOrientation = Portrait;
            UILaunchImageSize = "{375, 667}";
        },
                {
            UILaunchImageMinimumOSVersion = "7.0";
            UILaunchImageName = "LaunchImage-700-568h";
            UILaunchImageOrientation = Portrait;
            UILaunchImageSize = "{320, 568}";
        }
    );
    UIRequiredDeviceCapabilities =     (
        armv7
    );
    UISupportedInterfaceOrientations =     (
        UIInterfaceOrientationPortrait
    );
}

其中 “UILaunchImages” 里面就包含有我们需要的所有启动图,此时就可以拿到它做些文章。

核心代码:

/**
 操作启动图
 */
- (void)operateLaunchImage {
    // 1.获取LaunchImage
    __block NSString *launchImage = nil;
    NSArray<NSDictionary *> *imageArray = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
    [imageArray enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        CGSize lanuchImageSize = CGSizeFromString(obj[@"UILaunchImageSize"]);
        // 获取和当前屏幕尺寸等同的启动图(屏幕旋转方向不需要判断)
        if (CGSizeEqualToSize(lanuchImageSize, [UIScreen mainScreen].bounds.size)) {
            launchImage = obj[@"UILaunchImageName"];
        }
    }];
    // 2.添加到window上
    UIImageView *lanuchImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:launchImage]];
    lanuchImageView.frame = [UIScreen mainScreen].bounds;
    lanuchImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.window addSubview:lanuchImageView];
    
    // 3.设置你需要的动画或其他效果
    [UIView animateWithDuration:3.0f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        lanuchImageView.alpha = 0.0f;
        lanuchImageView.layer.transform = CATransform3DScale(CATransform3DIdentity, 1.2, 1.2, 1);
    } completion:^(BOOL finished) {
        [lanuchImageView removeFromSuperview];
    }];
}

这样就能拿到Launch Image 并操作它!

尊重作者劳动成果,转载请注明: 【kingdev】

posted @ 2016-04-14 10:04  Kingdev  阅读(507)  评论(0)    收藏  举报