平常开发中对于启动页可能会有一些特别的要求,比如在启动页加动画或加一些按键可以响应事件等,最近项目中要在启动页增加版本号,因为版本号是不断的改变,所以要动态实现把它加到启动页上;在XCode上面配置的Launch Images Source或Launch Screen FIle(IOS8以上会优先调用这个作为启动项)都是保存一张静态图片;

原理:

其实原理也是很简单,启动页还是运用Launch Images Source的内容,然后在做一个视图在最上层,视图的背景用启动项的那张图,让人误以为还在启动中,启动页加载完成后,就显示这层视图,在2秒后再把这层视图删除,产生一个过度的假启动页效果;而我们自定义的动作就可以在这层视图上进行;下面将通过Coding.net的APP讲解这个功能;

一:创建一个视图EaseStartView

EaseStartView.h文件内容:

#import <UIKit/UIKit.h>

@interface EaseStartView : UIView
+ (instancetype)startView; - (void)startAnimationWithCompletionBlock:(void(^)(EaseStartView *easeStartView))completionHandler;
@end

EaseStartView.m文件内容:

#import "EaseStartView.h"
#import <NYXImagesKit/NYXImagesKit.h>
#import "StartImagesManager.h" @interface EaseStartView ()
@property (strong, nonatomic) UIImageView *bgImageView, *logoIconView;
@property (strong, nonatomic) UILabel *descriptionStrLabel;
@end @implementation EaseStartView + (instancetype)startView{
UIImage *logoIcon = [UIImage imageNamed:@"logo_coding_top"];
StartImage *st = [[StartImagesManager shareManager] randomImage];
return [[self alloc] initWithBgImage:st.image logoIcon:logoIcon descriptionStr:st.descriptionStr];
} - (instancetype)initWithBgImage:(UIImage *)bgImage logoIcon:(UIImage *)logoIcon descriptionStr:(NSString *)descriptionStr{
self = [super initWithFrame:kScreen_Bounds];
if (self) {
//add custom code
UIColor *blackColor = [UIColor blackColor];
self.backgroundColor = blackColor; _bgImageView = [[UIImageView alloc] initWithFrame:kScreen_Bounds];
_bgImageView.contentMode = UIViewContentModeScaleAspectFill;
_bgImageView.alpha = 0.0;
[self addSubview:_bgImageView]; [self addGradientLayerWithColors:@[(id)[blackColor colorWithAlphaComponent:0.4].CGColor, (id)[blackColor colorWithAlphaComponent:0.0].CGColor] locations:nil startPoint:CGPointMake(0.5, 0.0) endPoint:CGPointMake(0.5, 0.4)]; _logoIconView = [[UIImageView alloc] init];
_logoIconView.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:_logoIconView];
_descriptionStrLabel = [[UILabel alloc] init];
_descriptionStrLabel.font = [UIFont systemFontOfSize:];
_descriptionStrLabel.textColor = [UIColor colorWithWhite:1.0 alpha:0.5];
_descriptionStrLabel.textAlignment = NSTextAlignmentCenter;
_descriptionStrLabel.alpha = 0.0;
[self addSubview:_descriptionStrLabel]; [_descriptionStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(@[self, _logoIconView]);
make.height.mas_equalTo();
make.bottom.equalTo(self.mas_bottom).offset(-);
make.left.equalTo(self.mas_left).offset();
make.right.equalTo(self.mas_right).offset(-);
}]; [_logoIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.top.mas_equalTo(kScreen_Height/);
make.width.mas_equalTo(kScreen_Width */);
make.height.mas_equalTo(kScreen_Width/ */);
}]; [self configWithBgImage:bgImage logoIcon:logoIcon descriptionStr:descriptionStr];
}
return self;
} - (void)configWithBgImage:(UIImage *)bgImage logoIcon:(UIImage *)logoIcon descriptionStr:(NSString *)descriptionStr{
bgImage = [bgImage scaleToSize:[_bgImageView doubleSizeOfFrame] usingMode:NYXResizeModeAspectFill];
self.bgImageView.image = bgImage;
self.logoIconView.image = logoIcon;
self.descriptionStrLabel.text = descriptionStr;
[self updateConstraintsIfNeeded];
} - (void)startAnimationWithCompletionBlock:(void(^)(EaseStartView *easeStartView))completionHandler{
[[UIApplication sharedApplication].keyWindow
addSubview:self];
[[UIApplication sharedApplication].keyWindow
bringSubviewToFront:self];
_bgImageView.alpha = 0.0;
_descriptionStrLabel.alpha = 0.0; @weakify(self);
[UIView animateWithDuration:2.0 animations:^{
@strongify(self);
self.bgImageView.alpha = 1.0;
self.descriptionStrLabel.alpha = 1.0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.6 delay:0.3 options:UIViewAnimationOptionCurveEaseIn animations:^{
@strongify(self);
[self setX:-kScreen_Width];
} completion:^(BOOL finished) {
@strongify(self);
[self removeFromSuperview];
if (completionHandler) {
completionHandler(self);
}
}];
}];
} @end

其实本实例中最为关键的内容在方法startAnimationWithCompletionBlock里

    [[UIApplication sharedApplication].keyWindow addSubview:self];
[[UIApplication sharedApplication].keyWindow bringSubviewToFront:self];

代码就是把这个视图设置成在最前的最上层,这样就可以盖住程序中的页面;

    _bgImageView.alpha = 0.0;
_descriptionStrLabel.alpha = 0.0;

这个是为了下面的动画做准备,若是直接用背景图可以把这两个都设置成0.99这样就不会有一闪的错觉;

    @weakify(self);
[UIView animateWithDuration:2.0 animations:^{
@strongify(self);
self.bgImageView.alpha = 1.0;
self.descriptionStrLabel.alpha = 1.0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.6 delay:0.3 options:UIViewAnimationOptionCurveEaseIn animations:^{
@strongify(self);
[self setX:-kScreen_Width];
} completion:^(BOOL finished) {
@strongify(self);
[self removeFromSuperview];
if (completionHandler) {
completionHandler(self);
}
}];
}];

这边是动画效果,时间设置为2秒,因为这边第一个动画完还有一个左移出启动页的效果;当动画结束后就可以  [self removeFromSuperview];

二:调用启动页视图

在AppDelegate中的didFinishLaunchingWithOptions进行调用;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; //网络
[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
[[AFNetworkReachabilityManager sharedManager] startMonitoring]; //设置导航条样式
[self customizeInterface];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade]; if ([Login isLogin]) {
[self setupTabViewController];
}else{
[UIApplication sharedApplication].applicationIconBadgeNumber = ;
[self setupIntroductionViewController];
}
[self.window makeKeyAndVisible];
[FunctionIntroManager showIntroPage]; EaseStartView *startView = [EaseStartView startView];
@weakify(self);
[startView startAnimationWithCompletionBlock:^(EaseStartView *easeStartView) {
@strongify(self);
//可以做其它事情
}]; return YES;
}

注意,EaseStartView代码的位置是要放在最后面,因为要让它盖在最上层,就要后面加载,这样就可以盖在登录页面上面或者主页上;到这就已经可以成功启动页的效果;

三:下面实例为项目中用到的动态加载版本号到启动页上

#import "StartUpView.h"

@interface StartUpView()
@property (strong, nonatomic) UIImageView *bgImageView;
@property (strong, nonatomic) UILabel *descriptionStrLabel;
@end @implementation StartUpView + (instancetype)startView
{
UIImage *bgImage=kshamLaunchImage;
return [[self alloc] initWithBgImage:bgImage];
} - (instancetype)initWithBgImage:(UIImage *)bgImage
{
self = [super initWithFrame:Main_Screen_Bounds];
if (self) { _bgImageView = [[UIImageView alloc] initWithFrame:Main_Screen_Bounds];
_bgImageView.contentMode = UIViewContentModeScaleAspectFill;
_bgImageView.alpha = ;
_bgImageView.image=bgImage;
[self addSubview:_bgImageView]; _descriptionStrLabel = [[UILabel alloc] init];
_descriptionStrLabel.font = [UIFont systemFontOfSize:];
_descriptionStrLabel.textColor = [UIColor blackColor];
_descriptionStrLabel.textAlignment = NSTextAlignmentCenter;
_descriptionStrLabel.alpha = ;
_descriptionStrLabel.text=[NSString stringWithFormat:@"版本号为:%@",appVersion];
[self addSubview:_descriptionStrLabel]; [_descriptionStrLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo();
make.bottom.equalTo(self.mas_bottom).offset(-);
make.left.equalTo(self.mas_left).offset();
make.right.equalTo(self.mas_right).offset(-);
}];
}
return self;
} - (void)startAnimationWithCompletionBlock:(void(^)(StartUpView *easeStartView))completionHandler{
[[UIApplication sharedApplication].keyWindow addSubview:self];
[[UIApplication sharedApplication].keyWindow bringSubviewToFront:self];
_bgImageView.alpha = 0.99;
_descriptionStrLabel.alpha = 0.99; @weakify(self);
[UIView animateWithDuration:2.0 animations:^{
@strongify(self);
self.bgImageView.alpha = 1.0;
self.descriptionStrLabel.alpha = 1.0;
} completion:^(BOOL finished) {
[self removeFromSuperview];
if (completionHandler) {
completionHandler(self);
}
}];
}
@end

最近有个妹子弄的一个关于扩大眼界跟内含的订阅号,每天都会更新一些深度内容,在这里如果你感兴趣也可以关注一下(嘿对美女跟知识感兴趣),当然可以关注后输入:github 会有我的微信号,如果有问题你也可以在那找到我;当然不感兴趣无视此信息;

iOS关于启动页自定义特殊处理的更多相关文章

  1. ios 2017启动页(Launch Screen Images)、图标(App Icon)尺寸大小

    ios 2017启动页(Launch Screen Images).图标(App Icon)尺寸大小   iPhone Portrait iOS 8,9-Retina HD 5.5 (1242×220 ...

  2. iOS swift 启动页加载广告(图片广告+视频广告)

    一般app在启动的时候都会有广告页,广告页用来加载自己的或者第三方的广告,广告的展示形式也多种多样,最近在看swift相关的东西,这里将提供支持加载图片广告和视频广告的解决方案 思路: 我们知道在加载 ...

  3. phonegap ios默认启动页

    phonegap创建的项目默认的启动界面是phonegap的图标,想去掉这个图标,有两个方法,第一就是将resourece下面的splash文件下面的图片改成自己想要的启动页面,名字要相同,替换掉它默 ...

  4. App启动页设计实例与技巧

    App启动页,也称闪屏页,最初是为缓解用户等待Web/iOS/Android App数据加载的焦虑情绪而出现,后被设计师巧妙用于品牌文化展示,服务特色介绍以及功能界面熟悉等平台进行设计,被赋予了更加丰 ...

  5. 【IOS】模仿"抽屉新热榜"动态启动页YFSplashScreen

    IOS最好要设置系统默认启动页面,不然进入应用就会突然闪现黑色画面 下图是我们要实现的效果: 总体思路:设置一个系统默认启动页面,在进入didFinishLaunchingWithOptions时, ...

  6. [摘抄]iOS App icon、启动页、图标规范

    以下内容都是我在做App时通过自己的经验和精品的分析得来的,希望会帮助到你.但是有时个别情况也要个别分析,要活学活用. 一. App  Icon 在设计iOS App Icon时,设计师不需要切圆角, ...

  7. iOS启动页设置

    点击项目->TARGETS->App Icons and Launch Images->Launch Images Source->Use Asset Catalog...-& ...

  8. [iOS]利用Appicon and Launchimage Maker生成并配置iOSApp的图标和启动页

    一.先来研究下这个软件->Appicon and Launchimage Maker 首先打开你电脑上的AppStore,然后搜索:AppIcon 然后回车: 这里我们先使用免费版的点击下载.( ...

  9. iOS LaunchScreen设置启动图片,启动页停留时间

    [新建的iOS 项目启动画面默认为LaunchScreen.xib] 如果想实现一张图片作为启动页,如下图

随机推荐

  1. html/css基础篇——html代码编写过程中的几个警惕点

    本文想说的警惕点与浏览器兼容无关,主要是几个本人在项目中遇到的几个小问题的总结,问题虽小,但是却有时很困扰人,在此记录一下,如果后期有此类问题会持续添加到这里. 1.内联标签之间的空格 正常情况下书写 ...

  2. ECharts+BaiduMap+HT for Web网络拓扑图应用

    前一篇谈及到了ECharts整合HT for Web的网络拓扑图应用,后来在ECharts的Demo中看到了有关空气质量的相关报表应用,就想将百度地图.ECharts和HT for Web三者结合起来 ...

  3. Web实时通信

    学习SignalR,可以从<实时数据显示--SignalR实例演示>http://www.cnblogs.com/insus/p/5619422.html 开始. 此篇只是把数据库的数据实 ...

  4. 组件Newtonsoft.Json实现object2json转换

    很多情况下,我们需要把数据类型做一些转换,供其它外部的子系统调用. 最为典型的是生成json格式供javascript作调用. 现成的组件Newtonsoft.Json可以实现object2json之 ...

  5. ubuntu16.4下用jexus部署asp.net core rtm

    上篇文章介绍了下用vs发布部署到iis环境,今天说下ubuntu 下部署asp.net core,不需要安装.net core sdk,自带运行时方式部署,利用jexus服务器转发请求到asp.net ...

  6. 泛函编程(31)-泛函IO:Free Monad-Running free

    在上节我们介绍了Free Monad的基本情况.可以说Free Monad又是一个以数据结构替换程序堆栈的实例.实际上Free Monad的功能绝对不止如此,以heap换stack必须成为Free M ...

  7. [moka同学笔记]二、Yii2.0课程笔记(魏曦老师教程)

    一.在标签tags的model中 //使用正则表达式,把标签字符串转换成数组 public static function string2array($tags) { return preg_spli ...

  8. sso demo 取消https (cas)

    基本配置 参考之前得随笔  http://www.cnblogs.com/rocky-fang/p/5354947.html 1. 修改tomcat-cas 配置 1.1 在 D:\test\sso\ ...

  9. 最短的数字判断代码 js

    转自  http://www.cnblogs.com/snandy/p/3590186.html 我们知道JavaScript提供了typeof运算符,因此最容易想到的是用typeof来判断是否是nu ...

  10. ubuntu 14.04 解决JavaMelody 图片中文乱码

    从windows系统中,copy了MSYH.TTC和MSYHBD.TTC 2个文件到 服务器的%JAVA_HOME%\jre\lib\fonts\fallback 目录中, (如果fallback目录 ...