美文网首页
iOS 延迟启动页以及启动页动画

iOS 延迟启动页以及启动页动画

作者: 叩首问路梦码为生 | 来源:发表于2019-03-28 14:38 被阅读0次

1、单纯的延长启动页


UIImageView *lanuchImgV;
  UIImageView *loadImgV;

-(void)delayAnimotion{
    // 注意:一定要在[self.window makeKeyAndVisible]之后添加imageView
    lanuchImgV = [[UIImageView alloc] initWithFrame:self.window.bounds];
    lanuchImgV.image = [self launchImage];
    [self.window addSubview:lanuchImgV];
    [self.window bringSubviewToFront:lanuchImgV];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:0.7 animations:^{
            lanuchImgV.alpha = 0.05;
            lanuchImgV.transform = CGAffineTransformMakeScale(1.5, 1.5);
        } completion:^(BOOL finished) {
            [lanuchImgV removeFromSuperview];
        }];
        
    });

// 获取启动页图片
- (UIImage *)launchImage
{
    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;
}


}


2、启动页动画


-(void)animotion{
    // 注意:一定要在[self.window makeKeyAndVisible]之后添加imageView
    lanuchImgV = [[UIImageView alloc] initWithFrame:self.window.bounds];
    lanuchImgV.image = [self launchImage];
    [self.window addSubview:lanuchImgV];
    [self.window bringSubviewToFront:lanuchImgV];
    // 这里做了0.8秒的延迟执行,因为我发现如果不做延迟,动画执行会有卡顿现象,具体原因不明,有知道的烦请告知下
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self showLoadImg];
        //        [UIView animateWithDuration:1.2 animations:^{
        //            launchImageView.alpha = 0.0;
        //            launchImageView.transform = CGAffineTransformMakeScale(1.2, 1.2);
        //        } completion:^(BOOL finished) {
        //            [launchImageView removeFromSuperview];
        //        }];
    });
}

- (UIImage *)launchImage
{
    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;
}


- (void)showLoadImg {
    loadImgV = [[UIImageView alloc] init];
    loadImgV.backgroundColor = [UIColor clearColor];
    if (Is_Iphone_X) {
        loadImgV.frame = CGRectMake(ScreenWidth/2-78, 433, 155, 12);
    }else {
        if (ScreenHeight == 480) {
            loadImgV.frame = CGRectMake(ScreenWidth/2-78, 243, 155, 12);
        }else if (ScreenHeight == 568) {
            loadImgV.frame = CGRectMake(ScreenWidth/2-78, 290, 155, 12);
        }else if (ScreenHeight == 1334/2) {
            loadImgV.frame = CGRectMake(ScreenWidth/2-78, 346, 155, 12);
        }else if (ScreenHeight == 2208/3) {
            loadImgV.frame = CGRectMake(ScreenWidth/2-78, 390, 155, 12);
        }
    }
    loadImgV.animationImages = [self animationImages]; //获取Gif图片列表
    loadImgV.animationDuration = 0.9;     //执行一次完整动画所需的时长
    loadImgV.animationRepeatCount = 1;  //动画重复次数
    [loadImgV startAnimating];
    [self.window addSubview:loadImgV];
    [self performSelector:@selector(hideLoadImg) withObject:self afterDelay:1.5];
}


#pragma mark -- 动画
- (NSMutableArray *)animationImages {
    NSMutableArray *imagesArr = [NSMutableArray array];
    for (int i = 3; i < 31; i++) {
        NSString *strImg = [NSString stringWithFormat:@"new_loading_%02d.png",i];
        NSString *path = [[NSBundle mainBundle] pathForResource:strImg ofType:nil];
        UIImage *image = [UIImage imageWithContentsOfFile:path];
        [imagesArr addObject:image];
    }
    return imagesArr;
}


- (void)hideLoadImg {
    loadImgV.hidden = YES;

    [UIView animateWithDuration:0.7 animations:^{
        lanuchImgV.alpha = 0.05;
        lanuchImgV.transform = CGAffineTransformMakeScale(1.5, 1.5);
    } completion:^(BOOL finished) {
        [loadImgV removeFromSuperview];
        [lanuchImgV removeFromSuperview];
    }];
    
}


相关文章

  • iOS 延迟启动页以及启动页动画

    1、单纯的延长启动页 2、启动页动画

  • iOS适配启动页

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

  • Flutter 启动页

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

  • iOS代码添加视图约束

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

  • iOS开发_启动页动画

    【作者前言】:13年入圈,分享些本人工作中遇到的点点滴滴那些事儿,17年刚开始写博客,高手勿喷!以分享交流为主,欢...

  • iOS 启动页带动画

    APP在启动的时候有的是静态图有的是动图,那怎么设置动图呢?本文主要介绍从网络上获取动图,这样可以只更改服务器上的...

  • iOS启动页动画效果

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

  • 你所知道 & 不知道的app启动页

    0 本文目录 1 什么是app启动页?2 为什么要有启动页?3 合理的启动页是什么样?4 iOS和android...

  • iOS LaunchImage启动页 标准尺寸

    iOS LaunchImage启动页 标准尺寸

  • 单读学习-启动页

    启动的时候会有一个启动页的动画,并且首次的时候会下载启动页的图片到本地 创建SplashActivity.java...

网友评论

      本文标题:iOS 延迟启动页以及启动页动画

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