博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IOS闪屏制作——程序启动动画
阅读量:7250 次
发布时间:2019-06-29

本文共 3058 字,大约阅读时间需要 10 分钟。

  hot3.png

首先,iOS 的 launch images 只能是静态图片

启动『动画』应该实际上是两部分,那张静态 launch image 作为起点,App 实际启动后播放完整的动画。

iOS软件开发中,通常在软件启动时需要创建一个闪屏显示欢迎信息,在显示闪屏的同时可以让程序在后台进行一些初始化工作,例如,检查网络连接、读取系统 设置等,等初始化工作完成以后再显示程序主界面,这里我们使用定时器来制作闪屏,在定时器到期以后,移除闪屏,显示程序主界面,并使用UIView的动画 方法使闪屏平滑过渡到主界面显示.

这里主要用到了定时器:

//NSTimer其实是将一个监听加入的系统的RunLoop中去,当系统runloop到如何timer条件的循环时,

//会调用timer一次,当timer执行完,也就是回调函数执行之后,timer会再一次的将自己加入到runloop中去继续监听
 

_timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fadeScreen)userInfo:nil repeats:NO];
代码:
#import "StartupScreenViewController.h"@interface StartupScreenViewController ()@end@implementation StartupScreenViewController@synthesize timer = _timer;@synthesize splashImageView = _splashImageView;@synthesize   mainViewController = mainviewController; //主界面 -(void)loadView{    CGRect appFrame = [[UIScreen mainScreen] applicationFrame];    UIView *view = [[UIView alloc] initWithFrame:appFrame];    view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;    self.view = view;    [view release];        _splashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"splash.png"]];    _splashImageView.frame = CGRectMake(0, 0, 320, 480);    [self.view addSubview:_splashImageView];    _viewController = [[MainViewController alloc] init];    _viewController.view.alpha = 0.0;    [self.view addSubview:viewController.view]; _timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(fadeScreen) userInfo:nil repeats:NO];}- (void)fadeScreen{    [UIView beginAnimations:nil context:nil];    [UIView setAnimationDuration:0.75];    [UIView setAnimationDelegate:self];    [UIView setAnimationDidStopSelector:@selector(finishedFading)];    self.view.alpha = 0.0;    [UIView commitAnimations];}- (void) finishedFading{    [UIView beginAnimations:nil context:nil];    [UIView setAnimationDuration:0.75];    self.view.alpha = 1.0;     viewController.view.alpha = 1.0;     [UIView commitAnimations];    [_splashImageView removeFromSuperview];}例子2:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];    // Override point for customization after application launch.    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];    self.window.rootViewController = self.viewController;    [self.window makeKeyAndVisible];        UIImageView *splashScreen = [[[UIImageView alloc] initWithFrame:self.window.bounds] autorelease];    splashScreen.image = [UIImage imageNamed:@"Default"];    [self.window addSubview:splashScreen];        [UIView animateWithDuration:1.0 animations:^{        CATransform3D transform = CATransform3DMakeScale(1.5, 1.5, 1.0);        splashScreen.layer.transform = transform;        splashScreen.alpha = 0.0;    } completion:^(BOOL finished) {        [splashScreen removeFromSuperview];    }];        return YES;} 

转载于:https://my.oschina.net/amoyai/blog/94988

你可能感兴趣的文章
cocos2d-x (js-binding)游戏开发解决方案设计稿
查看>>
改善Python程序的91个建议
查看>>
简单说说 angular.json 文件
查看>>
js-数据运算
查看>>
解决阿里云ECS运行前后台分离项目调用QQ互联导致: redirect uri is illegal(100010)问题...
查看>>
Slog48_项目上线之域名的备案
查看>>
[ 一起学React系列 -- 1 ] 信笔说JSX
查看>>
homebrew报错问题解决
查看>>
肉眼看到的相同两个字串的不同
查看>>
ng-zorror@~0.6升级@^1在开发中有哪些差异
查看>>
微信小程序 request请求封装
查看>>
Git 学习
查看>>
ES6深入浅出 模块系统
查看>>
一道js闭包面试题的学习
查看>>
微信小程序(新)必备知识
查看>>
网站接入微信扫码登录并获取用户基本信息(微信开放平台)
查看>>
HTC VIVE Wave 概览
查看>>
Vue动态控制input的disabled属性
查看>>
TCP的局限性有哪些?
查看>>
【前端数据结构基础】栈
查看>>