兩種方式明棍,一種是使用系統(tǒng)自帶的乡革,按規(guī)則定義啟動圖片名稱即可,顯示為1秒摊腋,要想延長時間沸版,用[nsthread
sleepForTimeInterval:5.0],另一種就是自定義uiivew, 加到window中去⌒苏簦或者自定義一個UIViewController视粮。
1系統(tǒng)自帶方式
1.1 添加圖片
1,準(zhǔn)備圖片資源橙凳,放入工程中蕾殴,即可,默認(rèn)時間為1s
iOS設(shè)備現(xiàn)在有三種不同的分辨率:iPhone?320x480岛啸、iPhone?4?640x960钓觉、iPad?768x1024。以前程序的啟動畫面(圖片)只要準(zhǔn)備一個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默認(rèn)啟動圖片荧缘,如果沒有提供上面幾個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];??//其實這一行代碼也可以不加掰派,因為默認(rèn)情況下歡迎界面的時間只有一秒从诲,加這一句是為了延長
歡迎界面的展示時間到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時會去判斷當(dāng)前程序是否顯示狀態(tài)欄,以此來布導(dǎo)航欄的位置趟薄。
2自定義方法
3绽诚,在XXXAppDelegate.m的-?(BOOL)application:(UIApplication?*)application?didFinishLaunchingWithOptions:(NSDictionary*)launchOptions中通過使用uiview或uiimageview等控件自定義啟動畫面
3App圖標(biāo)添加
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引導(dǎo)頁開發(fā)
4.1UIScrollview+UIImageView方案
我們在第一次打開App的時候杭煎,通常不是直接進(jìn)入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 = [[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張圖片的引導(dǎo)頁雷恃。
怎么去判斷是不是第一次登陸呢疆股,需要用到NSUserDefaults類。
在didFinishLaunchingWithOptions:函數(shù)中可以這樣判斷:
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults objectForKey:@"FirstLoad"] == nil) {
[userDefaults setBool:NO forKey:@"FirstLoad"];
//顯示引導(dǎo)頁
}
4.2UIScrollview+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.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;
}
//動態(tài)加載引導(dǎo)頁圖片
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本地緩存引導(dǎo)圖片邏輯
+(BOOL)hasLoadLaunchView
{
BOOLloaded = [[[NSUserDefaultsstandardUserDefaults]valueForKey:kHasLoadLaunchView]boolValue];
returnloaded;
}
//刷新本地緩存的引導(dǎo)頁圖片數(shù)據(jù)
+ (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;
//下面是對該文件進(jìn)行制定路徑的保存
[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:后續(xù)在此進(jìn)行網(wǎng)絡(luò)請求唱凯,刪除本地文件,然后更新本地文件,然后重置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磕昼。但是這個窗口默認(rèn)的背景色是磨砂不透明的,因此還需要把它的背景色設(shè)為透明节猿。這樣看起來就像是全屏遮罩一樣票从,但是由于系統(tǒng)不認(rèn)為新的View是全屏的漫雕,所以上一個View也不會被unload。
YLSLockScreenViewController*lockScreenController = [[YLSLockScreenViewController alloc] init];
lockScreenController.modalPresentationStyle
= UIModalPresentationFormSheet;//窗口
[self.mainViewControllerpresentViewController: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.windowaddSubview:backgroundView];
建立一個view設(shè)置背景顏色調(diào)整alpha值
iOS模糊半透明效果實現(xiàn)
http://my.oschina.net/kevinvane/blog/129707
6參考鏈接
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)的(如圖)