iOS关于启动页自定义特殊处理
平常开发中对于启动页可能会有一些特别的要求,比如在启动页加动画或加一些按键可以响应事件等,最近项目中要在启动页增加版本号,因为版本号是不断的改变,所以要动态实现把它加到启动页上;在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关于启动页自定义特殊处理的更多相关文章
- 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 ...
- iOS swift 启动页加载广告(图片广告+视频广告)
一般app在启动的时候都会有广告页,广告页用来加载自己的或者第三方的广告,广告的展示形式也多种多样,最近在看swift相关的东西,这里将提供支持加载图片广告和视频广告的解决方案 思路: 我们知道在加载 ...
- phonegap ios默认启动页
phonegap创建的项目默认的启动界面是phonegap的图标,想去掉这个图标,有两个方法,第一就是将resourece下面的splash文件下面的图片改成自己想要的启动页面,名字要相同,替换掉它默 ...
- App启动页设计实例与技巧
App启动页,也称闪屏页,最初是为缓解用户等待Web/iOS/Android App数据加载的焦虑情绪而出现,后被设计师巧妙用于品牌文化展示,服务特色介绍以及功能界面熟悉等平台进行设计,被赋予了更加丰 ...
- 【IOS】模仿"抽屉新热榜"动态启动页YFSplashScreen
IOS最好要设置系统默认启动页面,不然进入应用就会突然闪现黑色画面 下图是我们要实现的效果: 总体思路:设置一个系统默认启动页面,在进入didFinishLaunchingWithOptions时, ...
- [摘抄]iOS App icon、启动页、图标规范
以下内容都是我在做App时通过自己的经验和精品的分析得来的,希望会帮助到你.但是有时个别情况也要个别分析,要活学活用. 一. App Icon 在设计iOS App Icon时,设计师不需要切圆角, ...
- iOS启动页设置
点击项目->TARGETS->App Icons and Launch Images->Launch Images Source->Use Asset Catalog...-& ...
- [iOS]利用Appicon and Launchimage Maker生成并配置iOSApp的图标和启动页
一.先来研究下这个软件->Appicon and Launchimage Maker 首先打开你电脑上的AppStore,然后搜索:AppIcon 然后回车: 这里我们先使用免费版的点击下载.( ...
- iOS LaunchScreen设置启动图片,启动页停留时间
[新建的iOS 项目启动画面默认为LaunchScreen.xib] 如果想实现一张图片作为启动页,如下图
随机推荐
- 定义通用的可通过lambda表达式树来获取属性信息
我们一般获取某个类型或对象的属性信息均采用以下几种方法: 一.通过类型来获取属性信息 var p= typeof(People).GetProperty("Age");//获取指定 ...
- LINQ的ElementAt与ElementAtOrDefault方法
2个方法,均返回集合中指定索引的元素.区别在于前者当没有结果返回时,抛出异常,而后者如果没有结果则返回默认值. 参考例子: 上图示例中,红色数字是集合的索引,它是从0开始.只要知道它是从0开始,那下面 ...
- C#多种方式获取文件路径
string str5=Application.StartupPath;//获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称. string str1 =Process.GetCurren ...
- Ajax实现定时刷新页面
function deleteValue(){ var refresh = function() { $.ajax({ type:'post', url:'/Application/index ...
- [前端]使用JQuery UI Layout Plug-in布局 - wolfy
引言 使用JQuery UI Layout Plug-in布局框架实现快速布局,用起来还是挺方便的,稍微研究了一下,就能上手,关于该布局框架的材料,网上也挺多的.在项目中也使用到了,不过那是前端的工作 ...
- Castle ActiveRecord框架学习(二):快速搭建简单博客网站
一.数据库 1.数据表 Category:类别标签表(字段Type=1为类别,Type=2为标签) Category_Post:类别标签与文章中间表 Post:文章表 Comment:评论表 2.数据 ...
- SCC重新建图
Tarjan或Kosaraju算法[对每个点归类belong]求出SCC之后,对num_scc个SCC重新建图,针对不同问题,考虑重边的问题. //************************** ...
- 点击div折叠
<!doctype html> <html> <head> <meta charset="utf-8"> <meta cont ...
- student表中创建触发器,实现student表和student _course表的级联删除
create trigger Delete_sc on student for delete as delete student_course where student_course.s_no in ...
- Map遍历两种方式
Java代码 Map<String,String> map=new HashMap<String,String>(); map.put("username" ...