iOS 启动页

两种方式,一种是使用系统自带的,按规则定义启动图片名称即可,显示为1秒,要想延长时间,用[nsthread

sleepForTimeInterval:5.0],另一种就是自定义uiivew, 加到window中去。或者自定义一个UIViewController。

1系统自带方式

1.1 添加图片

1,准备图片资源,放入工程中,即可,默认时间为1s

iOS设备现在有三种不同的分辨率:iPhone 320x480、iPhone 4 640x960、iPad 768x1024。以前程序的启动画面(图片)只要准备一个Default.png就可以了,但是现在变得复杂多了。下面就是CocoaChina会员做得总结

如果一个程序,既支持iPhone又支持iPad,那么它需要包含下面几个图片:

Default-Portrait.png iPad专用竖向启动画面768x1024或者768x1004

Default-Landscape.png iPad专用横向启动画面1024x768或者1024x748

Default-PortraitUpsideDown.png iPad专用竖向启动画面(Home按钮在屏幕上面),可省略768x1024或者768x1004

Default-LandscapeLeft.png iPad专用横向启动画面,可省略1024x768或者1024x748

Default-LandscapeRight.png iPad专用横向启动画面,可省略1024x768或者1024x748

Default.png iPhone默认启动图片,如果没有提供上面几个iPad专用启动图片,则在iPad上运行时也使用Default.png(不推荐)320x480或者320x460

Default@2x.png iPhone4启动图片640x960或者640x920

为了在iPad上使用上述的启动画面,你还需要在info.plist中加入key: UISupportedInterfaceOrientations。同时,加入值UIInterfaceOrientationPortrait, UIInterfacOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight。

1.2延迟时间

2,如果想想设启动画面的显示时间,

在XXXAppDelegate.m的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions方法中插入以下一行代码:

// Insert delay of 5 seconds befor the splash screen disappers.

[NSThread sleepForTimeInterval:5.0];  //其实这一行代码也可以不加,因为默认情况下欢迎界面的时间只有一秒,加这一句是为了延长

欢迎界面的展示时间到5秒,时间大家可以自己定义。

1.3启动时显示状态栏

•在-info.plist文件中加入选项"Status bar is initially

hidden",值为YES

在AppDelegate.m文件中的- (BOOL)application:(UIApplication

*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法内加入代码:[[UIApplication sharedApplication] setStatusBarHidden:NO];

【注意】

如果你的程序同时使用了导航栏作为根视图控制器UINavigationController,则应该将语句[[UIApplication sharedApplication] setStatusBarHidden:NO]放在[self.window makeKeyAndVisible];之前,否则会出现状态栏与导航栏重叠的情况。可能是因为调用makeKeyAndVisible时会去判断当前程序是否显示状态栏,以此来布导航栏的位置。

2自定义方法

3,在XXXAppDelegate.m的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions中通过使用uiview或uiimageview等控件自定义启动画面

3App图标添加

The app icon set named "AppIcon" did not have anyapplicable content.

Solution:

icon 的大小注意长宽一样,不然报错:The app icon set named "AppIcon" did not have anyapplicable content.

http://www.cnblogs.com/xuzhong/p/3775975.html

4引导页开发

4.1UIScrollview+UIImageView方案

我们在第一次打开App的时候,通常不是直接进入App主界面,而是会有一个能左右滑动、介绍App功能的界面。我是用NSUserDefaults + UIScrollview实现。

新建一个类,继承UIView,假设名为Guide。在initWithFrame方法里:

CGFloat screenHeight = [UIScreenmainScreen].bounds.size.height;

UIScrollView* scrollView =[[UIScrollView alloc] initWithFrame:frame];

scrollView.backgroundColor =[UIColor whiteColor];

scrollView.showsHorizontalScrollIndicator = NO;

scrollView.showsVerticalScrollIndicator = NO;

scrollView.contentSize =CGSizeMake(320*4, screenHeight);

scrollView.pagingEnabled = YES;

for (int i=0; i<4; i++) {

UIImageView* imageView =[[UIImageView alloc initWithFrame:CGRectMake(i*320, 0, 320, screenHeight)];

imageView.contentMode =UIViewContentModeScaleAspectFill;

NSString *filePath = [[NSBundlemainBundle] pathForResource:

[NSStringstringWithFormat:@"FileName"

ofType:@"FileType"];

imageView.image = [UIImageimageWithContentsOfFile:filePath];

[scrollView addSubview:imageView];

if (i == 3) {

UIButton* start = [UIButtonbuttonWithType:UIButtonTypeCustom];

start.frame = CGRectMake(0,0,100,44);

start.layer.cornerRadius =5;

start.layer.borderWidth =0.5;

[start setCenter:CGPointMake(1120, iPhone5?450:400)];

[start setTitleColor:[UIColorgrayColor] forState:UIControlStateNormal];

[start addTarget:selfaction:@selector(closeView) forControlEvents:UIControlEventTouchUpInside];

[start setTitle:@"Start"forState:UIControlStateNormal];

[scrollView addSubview:start];

}

这样,就有了一个有4张图片的引导页。

怎么去判断是不是第一次登陆呢,需要用到NSUserDefaults类。

在didFinishLaunchingWithOptions:函数中可以这样判断:

NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];

if([userDefaults objectForKey:@"FirstLoad"] == nil) {

[userDefaults setBool:NO forKey:@"FirstLoad"];

//显示引导页

}

4.2UIScrollview+UIPageControl

ios用户引导页

http://blog.csdn.net/wanglj7525/article/details/43408809

http://www.open-open.com/lib/view/open1411201907593.html

http://blog.csdn.net/yesjava/article/details/7894663

@interface WelcomeViewController ()

@end

@implementation WelcomeViewController

- (void)viewDidLoad {

[super viewDidLoad];

[self setupScrollView];

[self setupPageControl];

}

//创建程序第一次加载要显示的视图

- (void)setupScrollView

{

CGRect r = [[UIScreen mainScreen] applicationFrame];

UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];

scrollView.delegate =self;

[self.view addSubview:scrollView];

//关闭水平方向上的滚动条

scrollView.showsHorizontalScrollIndicator =NO;

//是否可以整屏滑动

scrollView.pagingEnabled =YES;

scrollView.tag =200;

scrollView.contentSize =CGSizeMake(r.size.width *3, [UIScreen mainScreen].bounds.size.height);

for (int i = 0; i < 3; i++) {

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(r.size.width * i,0,r.size.width, [UIScreen mainScreen].bounds.size.height)];

imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"t%d_full", i +1]ofType:@"jpg"]];

[scrollView addSubview:imageView];

}

UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];

button.backgroundColor=[UIColor darkGrayColor];

[button setTitle:@"开始体验" forState:UIControlStateNormal];

button.frame=CGRectMake(r.size.width*2+r.size.width/2-50, [UIScreen mainScreen].bounds.size.height -80, 100, 30);

[button addTarget:self action:@selector(showDocList) forControlEvents:UIControlEventTouchUpInside];

[button setImage:[UIImage imageNamed:@"start.png"] forState:UIControlStateNormal];

button.imageEdgeInsets=UIEdgeInsetsMake(0, 80, 0, 0);

button.titleEdgeInsets=UIEdgeInsetsMake(0, -40, 0, 20);

[scrollView addSubview:button];

}

//跳转到主页面

-(void)showDocList{

ScrollerViewController *mainList=[self.storyboard instantiateViewControllerWithIdentifier:@"mainNavigation"];

[self presentViewController:mainList animated:NO completion:nil];

}

- (void)setupPageControl

{

UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height -40, [UIScreen mainScreen].bounds.size.width, 20)];

pageControl.tag =100;

//设置表示的页数

pageControl.numberOfPages =3;

//设置选中的页数

pageControl.currentPage =0;

//设置未选中点的颜色

pageControl.pageIndicatorTintColor = [UIColor whiteColor];

//设置选中点的颜色

pageControl.currentPageIndicatorTintColor = [UIColor orangeColor];

//添加响应事件

[pageControl addTarget:self action:@selector(handlePageControl:)forControlEvents:UIControlEventValueChanged];

[self.view addSubview:pageControl];

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

UIPageControl *pagControl = (UIPageControl *)[self.view viewWithTag:100];

pagControl.currentPage = scrollView.contentOffset.x / [UIScreen mainScreen].bounds.size.width;

}

- (void)handlePageControl:(UIPageControl *)pageControl

{

//切换pageControl .对应切换scrollView不同的界面

UIScrollView *scrollView = (UIScrollView *)[self.view viewWithTag:200];

//

[scrollView setContentOffset:CGPointMake(320 * pageControl.currentPage,0)animated:YES];

}

4.3第三方库MYBlurIntroductionView方案

4.3.1设计思路

新建一个LaunchVC,然后在RootVC中以模态窗口的方式弹出此VC。引导页采用本地缓存方式,支持从服务端动态加载然后更新显示。

4.3.2LaunchVC弹出逻辑

LaunchVC弹出逻辑(注意只加载一次):

if(![MDUtilityhasLoadLaunchView]) {

_launchVC= [[MDLaunchViewControlleralloc]init];

[self.navigationControllerpresentViewController:_launchVCanimated:NOcompletion:nil];

}

4.3.3LaunchVC初始化逻辑

LaunchVC初始化逻辑:

- (void)viewDidLoad {

[superviewDidLoad];

[selfinitSubViews];

// Do

any additional setup after loading the view.

}

-(void) initSubViews

{

if(!_introductView) {

[selfinitIntroductView];

}

}

-(void)initIntroductView

{

NSArray*launchImgFileArr = [MDUtilitygetLaunchImgFilePathArr];

if([launchImgFileArrcount] <=0) {

return;

}

//动态加载引导页图片

NSMutableArray*panelMArr = [[NSMutableArrayalloc]init];

for(NSString*imgFileinlaunchImgFileArr) {

//Create Stock Panel With Image

//MYIntroductionPanel*launchView = [[MYIntroductionPanel alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height) title:nildescription:nil image:[UIImage imageWithContentsOfFile:imgFile]];

MDLaunchView*launchView = [[MDLaunchViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)WithbackImg:[UIImageimageWithContentsOfFile:imgFile]];

[panelMArraddObject:launchView];

}

//Create

the introduction view and set its delegate

MYBlurIntroductionView*introductionView = [[MYBlurIntroductionViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];

introductionView.delegate=self;

//introductionView.BackgroundImageView =[UIImage imageNamed:@"Toronto, ON.jpg"];

//introductionView.LanguageDirection

= MYLanguageDirectionRightToLeft;

_introductView= introductionView;

//Build

the introduction with desired panels

[introductionViewbuildIntroductionWithPanels:panelMArr];

//Add

the introduction to your view

[self.viewaddSubview:introductionView];

}

4.3.4本地缓存引导图片逻辑

+(BOOL)hasLoadLaunchView

{

BOOLloaded = [[[NSUserDefaultsstandardUserDefaults]valueForKey:kHasLoadLaunchView]boolValue];

returnloaded;

}

//刷新本地缓存的引导页图片数据

+ (void)loadLaunchImgData

{

//获取Documents目录路径

NSArray*paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString*docDir

= [pathsobjectAtIndex:0];

NSString*launchDir = [docDirstringByAppendingString:@"/LaunchImg"];

NSFileManager*

fm=[NSFileManagerdefaultManager];

//NSString *imagePath = [[NSBundlemainBundle] pathForResource:@"22" ofType:@"jpg"];

if(![fmfileExistsAtPath:launchDir]){

NSError*error =nil;

//下面是对该文件进行制定路径的保存

[fmcreateDirectoryAtPath:launchDirwithIntermediateDirectories:YESattributes:nilerror:nil];

NSString*sourcePath = [[NSBundlemainBundle]pathForResource:@"1"ofType:@"jpg"];

NSString*toPath = [launchDirstringByAppendingString:@"/1.jpg"];

[fmcopyItemAtPath:sourcePathtoPath:toPatherror:&error];

if(error) {

return;

}

//[[self class] copyFile:sourcePathTo:toPath];

sourcePath = [[NSBundlemainBundle]pathForResource:@"2"ofType:@"jpg"];

toPath = [launchDirstringByAppendingString:@"/2.jpg"];

[fmcopyItemAtPath:sourcePathtoPath:toPatherror:&error];

if(error) {

return;

}

sourcePath = [[NSBundlemainBundle]pathForResource:@"3"ofType:@"jpg"];

toPath = [launchDirstringByAppendingString:@"/3.jpg"];

[fmcopyItemAtPath:sourcePathtoPath:toPatherror:&error];

if(error) {

return;

}

sourcePath = [[NSBundlemainBundle]pathForResource:@"4"ofType:@"jpg"];

toPath = [launchDirstringByAppendingString:@"/4.jpg"];

[fmcopyItemAtPath:sourcePathtoPath:toPatherror:&error];

if(error) {

return;

}

[[NSUserDefaultsstandardUserDefaults]setValue:[NSNumbernumberWithBool:NO]forKey:kHasLoadLaunchView];

}

else

{

[[NSUserDefaultsstandardUserDefaults]setValue:[NSNumbernumberWithBool:YES]forKey:kHasLoadLaunchView];

///TODO:后续在此进行网络请求,删除本地文件,然后更新本地文件,然后重置kHasLoadLaunchView值为NO

}

}

+(NSArray*)getLaunchImgFilePathArr

{

NSArray*paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString*docDir = [pathsobjectAtIndex:0];

NSString*launchDir = [docDirstringByAppendingString:@"/LaunchImg"];

NSFileManager*

fm=[NSFileManagerdefaultManager];

//取得一个目录下得所有文件名

NSArray*files = [fmsubpathsAtPath:launchDir];

if([filescount] >0) {

NSMutableArray*filePathArr = [[NSMutableArrayalloc]init];

for(NSString*fpinfiles) {

[filePathArraddObject:[launchDirstringByAppendingString:[NSStringstringWithFormat:@"/%@",fp]]];

}

returnfilePathArr;

}

else

returnnil;

}

5半透明遮罩

5.1法一

我最后采取的方法,是present一个窗口化的ViewController。但是这个窗口默认的背景色是磨砂不透明的,因此还需要把它的背景色设为透明。这样看起来就像是全屏遮罩一样,但是由于系统不认为新的View是全屏的,所以上一个View也不会被unload。

YLSLockScreenViewController*lockScreenController = [[YLSLockScreenViewController alloc] init];

lockScreenController.modalPresentationStyle

= UIModalPresentationFormSheet;//窗口

[self.mainViewControllerpresentViewController:lockScreenController animated:YES completion:^(void){

lockScreenController.view.superview.backgroundColor = [UIColorclearColor];//背景色透明

}];

代码比较简单,需要注意的是,设置背景色透明的那行代码,需要写在completion block里,而且设置的不是controller.view.backgroundColor,而是controller.view.superview.backgroundColor。

iOS7实现全屏模态半透明页面的效果

http://www.open-open.com/lib/view/open1392707807819.html

5.2法二(good)

backgroundView = [[UIView alloc] init];

backgroundView.frame= CGRectMake(0, 0,kWidth,kHeight);

backgroundView.backgroundColor= [UIColor colorWithRed:(40/255.0f) green:(40/255.0f) blue:(40/255.0f)alpha:1.0f];

backgroundView.alpha= 0.4;

[self.view.windowaddSubview:backgroundView];

建立一个view设置背景颜色调整alpha值

iOS模糊半透明效果实现

http://my.oschina.net/kevinvane/blog/129707

6参考链接

IOS启动页面制作

http://my.oschina.net/xiahuawuyu/blog/169113

ios用户引导页

http://blog.csdn.net/wanglj7525/article/details/43408809

IOS用户引导界面示例

http://www.open-open.com/lib/view/open1411201907593.html

ios页面跳转

http://blog.csdn.net/yesjava/article/details/7894663

iOS开发UIScrollView制作APP引导页

http://jingyan.baidu.com/article/4dc40848a341dfc8d846f152.html

iOS引导页实现(一)

http://blog.csdn.net/lwjok2007/article/details/46516047

iOS启动时如何添加引导页面小demo

http://blog.csdn.net/yudandan10/article/details/42009511

IOS闪屏制作——程序启动动画

http://my.oschina.net/amoyai/blog/94988

ios实现引导页面效果

http://blog.csdn.net/leechee_1986/article/details/24850547

半透明遮罩是如何实现的(如图)

http://www.cocoachina.com/bbs/read.php?tid=94649

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容