iOS 啟動頁

兩種方式,一種是使用系統(tǒng)自帶的,按規(guī)則定義啟動圖片名稱即可,顯示為1秒,要想延長時間,用[nsthread

sleepForTimeInterval:5.0],另一種就是自定義uiivew, 加到window中去?;蛘咦远x一個UIViewController。

1系統(tǒng)自帶方式

1.1 添加圖片

1,準備圖片資源,放入工程中,即可,默認時間為1s

iOS設備現(xiàn)在有三種不同的分辨率:iPhone?320x480、iPhone?4?640x960、iPad?768x1024。以前程序的啟動畫面(圖片)只要準備一個Default.png就可以了,但是現(xiàn)在變得復雜多了。下面就是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啟動時顯示狀態(tài)欄

?在-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];之前,否則會出現(xiàn)狀態(tài)欄與導航欄重疊的情況。可能是因為調用makeKeyAndVisible時會去判斷當前程序是否顯示狀態(tài)欄,以此來布導航欄的位置。

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引導頁開發(fā)

4.1UIScrollview+UIImageView方案

我們在第一次打開App的時候,通常不是直接進入App主界面,而是會有一個能左右滑動、介紹App功能的界面。我是用NSUserDefaults + UIScrollview實現(xiàn)。

新建一個類,繼承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:函數(shù)中可以這樣判斷:

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];

}

//創(chuàng)建程序第一次加載要顯示的視圖

-?(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;

//設置表示的頁數(shù)

pageControl.numberOfPages?=3;

//設置選中的頁數(shù)

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中以模態(tài)窗口的方式彈出此VC。引導頁采用本地緩存方式,支持從服務端動態(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)加載引導頁圖片

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;

}

//刷新本地緩存的引導頁圖片數(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;

//下面是對該文件進行制定路徑的保存

[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ù)在此進行網絡請求,刪除本地文件,然后更新本地文件,然后重置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。但是這個窗口默認的背景色是磨砂不透明的,因此還需要把它的背景色設為透明。這樣看起來就像是全屏遮罩一樣,但是由于系統(tǒng)不認為新的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實現(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設置背景顏色調整alpha值

iOS模糊半透明效果實現(xiàn)

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開發(fā)UIScrollView制作APP引導頁

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

iOS引導頁實現(xiàn)(一)

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實現(xiàn)引導頁面效果

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

半透明遮罩是如何實現(xiàn)的(如圖)

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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容