平常开发中对于启动页可能会有一些特别的要求,比如在启动页加动画或加一些按键可以响应事件等,最近项目中要在启动页增加版本号,因为版本号是不断的改变,所以要动态实现把它加到启动页上;在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. 表单input项使用label,同时引用Bootstrap库,导致input点击效果区增大

    产品姐姐想法多,点击input项才能聚焦进行操作,点击外部不能有反应 好了...直入正题 为了让标签更加语义化,在表单项中,我们往往会使用label进行包裹 <label for="l ...

  2. Nancy 学习-视图引擎 继续跨平台

    前面一篇,讲解Nancy的基础,以及Nancy自宿主,现在开始学习视图引擎. Nancy 目前支持两种 一个是SSVE 一个是Razor.下面我们一起学习. The Super Simple View ...

  3. WinForm 简单蒙版实现控件遮盖

    在Web上面要实现一个遮罩层或者说是蒙版吧,有了DIV那不算什么难事,只要给div定好位置和大小,把颜色的Alpha值设一下就有透明的效果.不过在Winform中实现起来就没那么简单了事.尝试过用一个 ...

  4. 【人在江湖飘,哪有不带刀】神器Jumony

    大神博客:http://www.cnblogs.com/Ivony/p/3447536.html 项目地址:https://github.com/Ivony/Jumony 1.安装Jumony包 在N ...

  5. Oracle--(Hierarchical Queries)层级查询

    内容来自: Oracle® Database SQL Language Reference 11g Release 2 (11.2) E41084-03. empolyees表来自hr方案,wareh ...

  6. 点击页面任何位置隐藏div

    <include file="Public:header" /> <style type="text/css"> table{width ...

  7. 基于TCP和多线程实现无线鼠标键盘-GestureDetector

    为了实现无线鼠标,需要识别出用户在手机屏幕上的滑动动作,这就需要用到GestureDetector类. 首先是activity_main.xml: <LinearLayout xmlns:and ...

  8. mongodb命令使用大全(常用命令)

    数据库常用命令 1.Help查看命令提示 help db.help(); db.yourColl.help(); db.youColl.find().help(); rs.help(); 2.切换/创 ...

  9. 高性能 Windows Socket 组件 HP-Socket v3.0.2 正式发布

    HP-Socket 是一套通用的高性能 Windows Socket 组件包,包含服务端组件(IOCP 模型)和客户端组件(Event Select 模型),广泛适用于 Windows 平台的 TCP ...

  10. 每天一命令 git reset

    在使用git的时候不免遇到commit的时候commit了错误的代码的时候,这时候就需要用到git的常用命令之一  reset了. reset顾名思义为重置.重置的是HEAD指针,可以使HEAD指针移 ...