美文网首页
iOS 启动页添加版本号

iOS 启动页添加版本号

作者: 打不死的小怪兽 | 来源:发表于2017-04-27 14:28 被阅读434次

XCode中有LaunchScreen.storyboard或者LaunchScreen.xib,苹果默认使用的就是拿这个当启动页,这是一个静态的页面,也就是只能用自动布局来适配屏幕的大小,就一张图片居中显示,这个兼容性不强。另外一种方法,这种方法很多人都在用,只要设置正确 尺寸格式正确就可以正常显示的。常用的尺寸格式如下:

CA87F4BA-7F54-486B-9E8D-6B5AB1190D26.png B1A951D8-A8A2-43AB-B8F0-2EC86F61DCEA.png
步骤如下:

1、点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image"
2、如图,右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以及低版本的ios系统做支持.这边我选了ios8.0,ios7.0,ios6没有做支持.

55A47D57-7A6A-4DBD-91AD-B89C63CB2A8A.png

3、选择launchImage


975202FB-6791-4DD8-B1B0-521401F43097.png

4、清空Launch Screen File


72CB1773-D0F9-4466-814D-91DC7FA24454.png

5、加入版本号的代码

#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = [[ViewController alloc] init];
    [self.window makeKeyAndVisible];
    
    [self customLaunchImageView];

    return YES;
}
- (void)customLaunchImageView
{
    UIImageView *launchImageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
    launchImageView.image = [self getLaunchImage];
    [self.window addSubview:launchImageView];
    [self.window bringSubviewToFront:launchImageView];
    
    UILabel *vesionLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 260, 100, 30)];
    vesionLabel.backgroundColor = [UIColor cyanColor];
    //获取当前设备中应用的版本号
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    vesionLabel.text = [NSString stringWithFormat:@"V %@",currentVersion];
    vesionLabel.textAlignment = NSTextAlignmentCenter;
    [launchImageView addSubview:vesionLabel];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:1.2 animations:^{
            launchImageView.alpha = 0.0;
            launchImageView.transform = CGAffineTransformMakeScale(1.2, 1.2);
        } completion:^(BOOL finished) {
            [launchImageView removeFromSuperview];
        }];
    });
}

- (UIImage *)getLaunchImage
{
    UIImage *lauchImage = nil;
    NSString *viewOrientation = nil;
    CGSize viewSize = [UIScreen mainScreen].bounds.size;
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        
        viewOrientation = @"Landscape";
        
    } else {
        
        viewOrientation = @"Portrait";
    }
    
    NSArray *imagesDictionary = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
    for (NSDictionary *dict in imagesDictionary) {
        
        CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
        if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
            
            lauchImage = [UIImage imageNamed:dict[@"UILaunchImageName"]];
        }
    }
    return lauchImage;
}

运行结果:

3B27A049-EA3F-4F0E-A78D-B066EB5FDD9F.png

相关文章

  • iOS 启动页添加版本号

    XCode中有LaunchScreen.storyboard或者LaunchScreen.xib,苹果默认使用的就...

  • iOS代码添加视图约束

    项目要做这样一个效果的启动页。 考虑到版本号是会不断变更的,因此采用动画效果启动页,让版本号动态加载iOS启动页动...

  • iOS适配启动页

    iOS适配启动页 iOS适配启动页

  • ios 启动添加广告页

    由于ios启动页是有苹果的规范的,所以动态的修改启动页可能会有被拒的风险。关于这一点我没试过,如果想做是可以做的,...

  • Flutter 启动页

    启动页 IOS启动页,在ios/Runner/Assets.xcassets/LaunchImage.images...

  • Android 引导页

    引导页 思路1.判断当前系统版本号2.如果与保存版本号不相同启动引导页跳转主页面如果相同等待指定时间跳转启动页 创...

  • iOS启动页动画效果

    最近项目中要在启动页增加版本号,因为版本号是不断的改变,所以要动态实现把它加到启动页上;在XCode上面配置的La...

  • iOS LaunchImage启动页 标准尺寸

    iOS LaunchImage启动页 标准尺寸

  • iOS11 适配

    1、启动页 如果启动页采用 Launch Imaged Sourc,则需要添加iPhoneX的启动图,不然整个 A...

  • Flutter——启动页splash全屏效果实现

    Flutter官方自带的splash启动页是在android或者ios的文件里面设置,但是不能添加倒计时之类的效果...

网友评论

      本文标题:iOS 启动页添加版本号

      本文链接:https://www.haomeiwen.com/subject/nnggzttx.html