美文网首页iOS程序员iOS Developer
iOS开发:启动图动画效果

iOS开发:启动图动画效果

作者: 川农鉴黄师 | 来源:发表于2016-05-13 14:42 被阅读2104次

    效果如图:

    2016-05-13 13_52_11.gif

    由于项目需要在启动图后加载广告,所以把动画加载了广告页面。

    实现方法

    1.在appdelegate的didFinshLaunchingWithOptions方法里面实现如下代码:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    //这里设置window的根视图控制器
    areaVc = [[XSTAreaProvinceViewController alloc] init];
        UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:areaVc];
        nav.navigationBar.barTintColor = SET_COLOR(@"3FC1FF");
        nav.navigationBar.translucent = NO;
        areaVc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [nav.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
        self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
    //这里将启动图取出
    [self setLaunchImage];
    
    //设置状态栏为白色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    return YES;
    

    }
    1.启动后再一次从info.plist的字典里面获取到LunachImages(启动图的数组),接着把图片取出来加在window上,接着写个动画效果就行,因为你已经设置好window的根视图控制器,这里启动图加载的时间为默认
    具体实现代码:
    - (void)setLaunchImage{
    CGSize viewSize =self.window.bounds.size;//获取当前屏幕Size
    NSStringviewOrientation =@"Portrait";//横屏请设置成 @"Landscape"
    NSString
    launchImage =nil;

    //从info.plist文件中获取启动图的数组,这里会返回一个数组(里满是你设置好的启动图)
    NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
    for(NSDictionary* dict in imagesDict) {
        CGSize imageSize =CGSizeFromString(dict[@"UILaunchImageSize"]);
        这里取出数组里面和当前屏幕尺寸相同的iamge
        if(CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
    
            launchImage = dict[@"UILaunchImageName"];
        }
    }
    
    UIImageView * launchView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:launchImage]];
    
    launchView.frame=self.window.bounds;
    launchView.contentMode=UIViewContentModeScaleAspectFill;
    [self.window addSubview:launchView];
    //动画效果(你也可以这只其他,这种timeOut效果不错,用过MBProgressHUD人都知道)
     //在两秒内将alpha设置为0,之后在移除
    [UIView animateWithDuration:2.0f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState
                    animations:^{
                        launchView.alpha=0.0f;
                        launchView.layer.transform=CATransform3DScale(CATransform3DIdentity,1.2,1.2,1);
                    }
                    completion:^(BOOL finished) {
                        [launchView removeFromSuperview];
                }];
    }
    

    相关文章

      网友评论

      本文标题:iOS开发:启动图动画效果

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