iOS 启动页

2017-01-14 10:23:20来源:http://www.jianshu.com/p/97dae4ac2180作者:致id人点击

iOS启动页的设置有两种方式


方法一:
建一个LaunchImage




选择你所需要 显示的屏幕





设置删除掉Lauch Screen File





取消勾选 Use a Launch Screen



方法二:

直接在LaunchScreen.storyboard里面设置各种控件


以下为我实现的两种启动页动画效果:
用方式一:


实现思路:
1.在启动页之后,将UICollectionViewController作为根视图控制器,然后跳转(水波效果)到另一个视图控制器,最后在动画结束后跳转到主要视图控制器.
2.一般App第一次启动会有过渡动画,之后直接进入主题.所以用NSUserDefaults把版本号存储可以达到这一效果.



实现步骤如下:
1、设置启动页图片,没毛病!




启动页图片


2、封装一个工具类:@interface GuideTool : NSObject
实现两种启动方式的方法:
+ (UIViewController *)chooseRootViewController;


封装思路:
1.如果是第一次运行,就跳转到轮播图片的视图控制器;
2.如果运行两次以上,就跳转到插播广告的视图控制器


GuideTool.m


#import "AdViewController.h"
#import "GuideTool.h"
#import "NewFeatureCollectionViewController.h"
#define VersionKey @"curVersion"
@implementation GuideTool
+ (UIViewController *)chooseRootViewController {
UIViewController *rootVc = nil;
NSDictionary *dict = [NSBundle mainBundle].infoDictionary;
// 获取最新的版本号
NSString *curVersion = dict[@"CFBundleShortVersionString"];
// 获取上次的版本号
NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:VersionKey];
if ([curVersion isEqualToString:lastVersion]) {
// 版本号相等
rootVc = [[AdViewController alloc]init];
} else {
// 有新的版本号
// 保存到偏好设置
[[NSUserDefaults standardUserDefaults] setObject:curVersion forKey:VersionKey];
rootVc = [[NewFeatureCollectionViewController alloc] init];
}
return rootVc;
}
@end

3、轮播结束的点击方法:
NewFeatureCollectionViewController.m


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 4) {
// 切换跟视图控制器进行跳转
[UIApplication sharedApplication].keyWindow.rootViewController = [[AdViewController alloc] init];
// 水波动画
CATransition *anim = [CATransition animation];
anim.type = @"rippleEffect";
anim.duration = 1;
[[UIApplication sharedApplication].keyWindow.layer addAnimation:anim forKey:nil];
}
}

4、广告页面停留一段时间,放大动画再跳转
AdViewController.m


    self.adImageView.image = [UIImage imageNamed:@"ad"];
// 三秒之后移除
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.3f animations:^{
self.adImageView.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
self.adImageView.alpha = 0.f;
} completion:^(BOOL finished) {
MainViewController *vc = [[MainViewController alloc] init];
// 动画结束后,跳转到主界面
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
[UIApplication sharedApplication].keyWindow.rootViewController = nc;
[self presentViewController:nc animated:YES completion:nil];
}];
});

用方法二:


实现步骤如下:
1、在LaunchScreen.storyboard将view的背景颜色设置为绿色,再放入一张图片,做好约束




2、建立一个StartupViewController作为'过渡'视图控制器


    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [[StartupViewController alloc] init];
[self.window makeKeyAndVisible];

3、在StartupViewController.xib文件中,布置与启动页相同的控件,除此之外还加一个UILabel作为提示语




StartupViewController.m
延迟一秒的过渡动画:


    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView transitionWithView:self.imageView duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
self.imageView.image = [UIImage imageNamed:@"image01"];
} completion:nil];
self.textLabel.text = @"从零开始的异世界";
});

慢镜头放大效果:


    [UIView animateWithDuration:4 animations:^{
self.imageView.transform = CGAffineTransformMakeScale(1.1, 1.1);
}];

5、最后跳转到关键的视图控制器即可


    MainViewController *vc = [[MainViewController alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[UIApplication sharedApplication].keyWindow.rootViewController = nc;
[self presentViewController:nc animated:YES completion:nil];



最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台