總述:
????????兩種方式庭敦,一種是使用系統(tǒng)自帶的疼进,按規(guī)則定義啟動圖片名稱即可,顯示為1秒秧廉,要想延長時間伞广,用[nsthread sleepForTimeInterval:5.0],另一種就是自定義uiivew疼电,加到window中去嚼锄。
1 系統(tǒng)自帶方式
1.1 添加圖片
????1,準備圖片資源蔽豺,放入工程中区丑,即可,默認時間為1s
??????iOS設(shè)備現(xiàn)在有三種不同的分辨率:iPhone?320x480茫虽、iPhone?4?640x960刊苍、iPad?768x1024。以前程序的啟動畫面(圖片)只要準備一個?Default.png?就可以了濒析,但是現(xiàn)在變得復(fù)雜多了正什。下面就是?CocoaChina?會員做得總結(jié)。
? ? ? 如果一個程序号杏,既支持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,如果想想設(shè)啟動畫面的顯示時間骏啰,
在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 啟動時顯示狀態(tài)欄
? ? ? ? 在-info.plist 文件中加入選項 "Status bar is initially hidden", 值為YES
????????在 AppDelegate.m 文件中的 - (BOOL)application: (UIApplication*)application? didFinishLaunchingWithOptions: (NSDictionary *)launchOptions 方法內(nèi)加入代碼:???
[[UIApplication sharedApplication] setStatusBarHidden: NO];
【注意】
????????如果你的程序同時使用了導(dǎo)航欄作為根視圖控制器 UINavigationController,則應(yīng)該將語句 [[UIApplication sharedApplication] setStatusBarHidden:NO] 放在 [self.window makeKeyAndVisible]; 之前壁熄,否則會出現(xiàn)狀態(tài)欄與導(dǎo)航欄重疊的情況帚豪。可能是因為調(diào)用 makeKeyAndVisible 時會去判斷當前程序是否顯示狀態(tài)欄请毛,以此來布導(dǎo)航欄的位置志鞍。
2 自定義方法
3,在XXXAppDelegate.m的-?(BOOL)application:(UIApplication?*)application didFinishLaunchingWithOptions: (NSDictionary*)launchOptions中通過使用uiview或uiimageview等控件自定義啟動畫面方仿。
3 App圖標添加
參考鏈接:
http://www.cnblogs.com/xuzhong/p/3775975.html
? ? The app icon set named "AppIcon" did not have anyapplicable content.
????Solution:
????1.DeleteApp Icon segment in Images.xcassets.
????2.Createa new App Icon segment in Images.xcassets. (It will add all iOS device iconsize needness)
????3.Modifythe icon size to mach the icon size.
????4.Dropinto the icon set.
????5.Rebuild.
4 引導(dǎo)頁開發(fā)
4.1 UIScrollview+UIImageView方案
????????我們在第一次打開App的時候固棚,通常不是直接進入App主界面,而是會有一個能左右滑動仙蚜、介紹App功能的界面此洲。我是用NSUserDefaults + UIScrollview實現(xiàn)。
????????新建一個類委粉,繼承UIView呜师,假設(shè)名為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 = [[NSBundle mainBundle] pathForResource: [NSString stringWithFormat: @"FileName" ofType: @"FileType"];
? imageView.image = [UIImage imageWithContentsOfFile: filePath];
? [scrollView addSubview: imageView];
? if (i == 3) {
??? UIButton* start = [UIButton buttonWithType: 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: [UIColor grayColor] forState: UIControlStateNormal];
??? [start addTarget: self action: @selector(closeView) forControlEvents: UIControlEventTouchUpInside];
??? [start setTitle: @"Start" forState: UIControlStateNormal];
??? [scrollView addSubview: start];
? }
????????這樣贾节,就有了一個有4張圖片的引導(dǎo)頁汁汗。怎么去判斷是不是第一次登陸呢衷畦,需要用到NSUserDefaults類。在didFinishLaunchingWithOptions:函數(shù)中可以這樣判斷:
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults objectForKey: @"FirstLoad"] == nil) {
??? [userDefaults setBool: NO forKey: @"FirstLoad"];
??? //顯示引導(dǎo)頁
}
4.2 UIScrollview+UIPageControl
ios用戶引導(dǎo)頁
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];
}
//創(chuàng)建程序第一次加載要顯示的視圖
-?(void)setupScrollView
{
????CGRect?r?=?[[UIScreen?mainScreen]?applicationFrame];
????UIScrollView?*scrollView?=?[[UIScrollView?alloc] initWithFrame: [UIScreen?mainScreen].bounds];
????scrollView.delegate?=self;
????[self.view?addSubview: scrollView];
????//關(guān)閉水平方向上的滾動條
????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];
}
//跳轉(zhuǎn)到主頁面
- (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;
????//設(shè)置表示的頁數(shù)
????pageControl.numberOfPages?=3;
????//設(shè)置選中的頁數(shù)
????pageControl.currentPage?=0;
????//設(shè)置未選中點的顏色
????pageControl.pageIndicatorTintColor?=?[UIColor?whiteColor];
????//設(shè)置選中點的顏色
????pageControl.currentPageIndicatorTintColor?=?[UIColor?orangeColor];
????//添加響應(yīng)事件
????[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?.對應(yīng)切換scrollView不同的界面
????UIScrollView?*scrollView?=?(UIScrollView?*)[self.view?viewWithTag: 200];
????// [scrollView?setContentOffset: CGPointMake(320?*?pageControl.currentPage,0) animated: YES];
}
4.3 第三方庫MYBlurIntroductionView方案
4.3.1 設(shè)計思路
? ? ? ? 新建一個LaunchVC知牌,然后在RootVC中以模態(tài)窗口的方式彈出此VC祈争。引導(dǎo)頁采用本地緩存方式,支持從服務(wù)端動態(tài)加載然后更新顯示角寸。
4.3.2 LaunchVC彈出邏輯
????????LaunchVC彈出邏輯(注意只加載一次):
if (![HJUtility hasLoadLaunchView]) {
? ? _launchVC = [[HJLaunchViewController alloc] init];
? ? [self.navigationController presentViewController: _launchVC animated:NO completion: nil];
}
4.3.3 LaunchVC初始化邏輯
LaunchVC初始化邏輯:
- (void)viewDidLoad {
??? [super viewDidLoad];
??? [self initSubViews];
}
-(void) initSubViews
{
??? if (!_introductView) {
??????? [self initIntroductView];
??? }
}
-(void)initIntroductView
{
??? NSArray *launchImgFileArr = [HJUtility getLaunchImgFilePathArr];
??? if ([launchImgFileArr count] <= 0) {
??????? return;
??? }
??? //動態(tài)加載引導(dǎo)頁圖片
??? NSMutableArray *panelMArr = [[NSMutableArray alloc] init];
??? for (NSString *imgFile in launchImgFileArr) {
??????? //Create Stock Panel With Image
??????? HJLaunchView *launchView = [[HJLaunchView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) withbackImg: [UIImage imageWithContentsOfFile: imgFile]];
??????? [panelMArr addObject: launchView];
??? }
??? //Create the introduction view and set its delegate
??? MYBlurIntroductionView *introductionView = [[MYBlurIntroductionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
??? introductionView.delegate = self;
??? _introductView= introductionView;
??? //Build the introduction with desired panels
??? [introductionView buildIntroductionWithPanels: panelMArr];
??? //Add the introduction to your view
??? [self.view addSubview: introductionView];
}
4.3.4 本地緩存引導(dǎo)圖片邏輯
+ (BOOL) hasLoadLaunchView
{
??? BOOL loaded = [[[NSUserDefaults standardUserDefaults] valueForKey: kHasLoadLaunchView] boolValue];
??? returnloaded;
}
//刷新本地緩存的引導(dǎo)頁圖片數(shù)據(jù)
+ (void) loadLaunchImgData
{
??? // 獲取Documents目錄路徑
??? NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
??? NSString *docDir = [paths objectAtIndex:0];
??? NSString*launchDir = [docDir stringByAppendingString: @"/LaunchImg"];
??? NSFileManager *fm= [NSFileManager defaultManager];
??? if(![fm fileExistsAtPath: launchDir]){
??????? NSError *error = nil;
??????? //下面是對該文件進行制定路徑的保存
??????? [fm createDirectoryAtPath: launchDir withIntermediateDirectories: YES attributes: nil error: nil];
??????? NSString *sourcePath = [[NSBundle mainBundle] pathForResource: @"1" ofType: @"jpg"];
??????? NSString *toPath = [launchDir stringByAppendingString: @"/1.jpg"];
??????? [fm copyItemAtPath: sourcePath toPath: toPath error: &error];
??????? if(error) {
??????????? return;
??????? }
??????? sourcePath = [[NSBundle mainBundle] pathForResource: @"2" ofType: @"jpg"];
??????? toPath = [launchDir stringByAppendingString: @"/2.jpg"];
??????? [fm copyItemAtPath: sourcePath toPath: toPath error: &error];
??????? if(error) {
??????????? return;
??????? }
??????? sourcePath = [[NSBundle mainBundle] pathForResource: @"3" ofType: @"jpg"];
??????? toPath = [launchDir stringByAppendingString: @"/3.jpg"];
??????? [fm copyItemAtPath: sourcePath toPath: toPath error: &error];
??????? if(error) {
??????????? return;
??????? }
??????? sourcePath = [[NSBundle mainBundle] pathForResource: @"4" ofType: @"jpg"];
??????? toPath = [launchDir stringByAppendingString: @"/4.jpg"];
??????? [fm copyItemAtPath: sourcePath toPath: toPath error: &error];
??????? if(error) {
??????????? return;
??????? }
??????? [[NSUserDefaults standardUserDefaults] setValue: [NSNumber numberWithBool: NO] forKey: kHasLoadLaunchView];
??? }
??? else
??? {
??????? [[NSUserDefaults standardUserDefaults] setValue: [NSNumber numberWithBool: YES] forKey: kHasLoadLaunchView];
??? }
}
+ (NSArray*) getLaunchImgFilePathArr
{
??? NSArray*paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
??? NSString*docDir = [paths objectAtIndex: 0];
??? NSString*launchDir = [docDir stringByAppendingString: @"/LaunchImg"];
??? NSFileManager* fm = [NSFileManager defaultManager];
??? //取得一個目錄下得所有文件名
??? NSArray*files = [fm subpathsAtPath: launchDir];
??? if([files count] > 0) {
??????? NSMutableArray *filePathArr = [[NSMutableArray alloc] init];
??????? for (NSString *fp in files) {
??????????? [filePathArr addObject: [launchDir stringByAppendingString: [NSString stringWithFormat: @"/%@", fp]]];
??????? }
??????? return filePathArr;
??? }
??? else
??????? return nil;
}
4.4 廣告倒數(shù)頁設(shè)計
????????除了功能引導(dǎo)頁壶笼,廣告倒數(shù)頁的加入也很有講究夏跷,主要思路是:
? ? ? ? 單獨定義一層UIWindow陡鹃,Level在功能引導(dǎo)頁之下算撮,在AppDelegate.window之上,在Alert之下亿柑。廣告頁自定義View也需要先加入到VC中邢疙,然后將該VC指定為UIWindow的rootVC,在AppDelegate.window加載完之后在初始化該window望薄,并makeKeyAndVisible秘症。
5 半透明遮罩
5.1 法一
????????我最后采取的方法,是present一個窗口化的ViewController式矫。但是這個窗口默認的背景色是磨砂不透明的乡摹,因此還需要把它的背景色設(shè)為透明。這樣看起來就像是全屏遮罩一樣采转,但是由于系統(tǒng)不認為新的View是全屏的聪廉,所以上一個View也不會被unload。
YLSLockScreenViewController *lockScreenController = [[YLSLockScreenViewController alloc] init];
lockScreenController.modalPresentationStyle = UIModalPresentationFormSheet;// 窗口
[self.mainViewController presentViewController: lockScreenController animated:YES completion:^(void){
???lockScreenController.view.superview.backgroundColor = [UIColorclearColor];//背景色透明
}];
????????代碼比較簡單故慈,需要注意的是板熊,設(shè)置背景色透明的那行代碼,需要寫在completion block里察绷,而且設(shè)置的不是controller.view.backgroundColor干签,而是controller.view.superview.backgroundColor。
iOS7實現(xiàn)全屏模態(tài)半透明頁面的效果
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.window addSubview: backgroundView];
????????建立一個view設(shè)置背景顏色??調(diào)整 alpha值
iOS模糊半透明效果實現(xiàn)
http://my.oschina.net/kevinvane/blog/129707
6 開發(fā)技巧
6.1 開發(fā)問題收集
6.1.1 20秒啟動超時閃退問題failedto scene-create after
????????IOS APP拆撼,如果啟動時間超過了20s容劳,操作系統(tǒng)就會自動將app關(guān)閉,導(dǎo)致app啟動不起來闸度。因此App啟動過程中竭贩,應(yīng)該盡量少在主線程中做耗時操作,如果一定需要莺禁,例如需要做一些串行請求留量,就要注意設(shè)置超時時間,而且應(yīng)該盡量短。
7 參考鏈接
IOS啟動頁面制作
http://my.oschina.net/xiahuawuyu/blog/169113
ios用戶引導(dǎo)頁
http://blog.csdn.net/wanglj7525/article/details/43408809
IOS用戶引導(dǎo)界面示例
http://www.open-open.com/lib/view/open1411201907593.html
ios頁面跳轉(zhuǎn)
http://blog.csdn.net/yesjava/article/details/7894663
iOS開發(fā)UIScrollView制作APP引導(dǎo)頁
http://jingyan.baidu.com/article/4dc40848a341dfc8d846f152.html
iOS引導(dǎo)頁實現(xiàn)(一)
http://blog.csdn.net/lwjok2007/article/details/46516047
iOS啟動時如何添加引導(dǎo)頁面 小demo
http://blog.csdn.net/yudandan10/article/details/42009511
IOS閃屏制作——程序啟動動畫
http://my.oschina.net/amoyai/blog/94988
ios實現(xiàn)引導(dǎo)頁面效果
http://blog.csdn.net/leechee_1986/article/details/24850547
半透明遮罩是如何實現(xiàn)的(如圖)
http://www.cocoachina.com/bbs/read.php?tid=94649
What does this crash report tell me about why my app failsto start?
Crash on launch because app is taking too long - deadlock -keychain
iOS app works on xCode but crash running from device.
https://pompidev.net/2014/11/16/ios-app-works-on-xcode-but-crash-running-from-device/
iOS嚴重問題解釋(crash)
http://blog.csdn.net/mtc1256/article/details/52595160
App rejection - Crash report says: failed to scene-create intime (badf00d) What is wrong?
iOS應(yīng)用啟動速度