iOS 啟動(dòng)頁

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

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

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

1.1 添加圖片

1,準(zhǔn)備圖片資源,放入工程中,即可,默認(rèn)時(shí)間為1s

iOS設(shè)備現(xiàn)在有三種不同的分辨率:iPhone?320x480、iPhone?4?640x960、iPad?768x1024。以前程序的啟動(dòng)畫面(圖片)只要準(zhǔn)備一個(gè)Default.png就可以了,但是現(xiàn)在變得復(fù)雜多了。下面就是CocoaChina會(huì)員做得總結(jié)

如果一個(gè)程序,既支持iPhone又支持iPad,那么它需要包含下面幾個(gè)圖片:

Default-Portrait.png?iPad專用豎向啟動(dòng)畫面768x1024或者768x1004

Default-Landscape.png?iPad專用橫向啟動(dòng)畫面1024x768或者1024x748

Default-PortraitUpsideDown.png?iPad專用豎向啟動(dòng)畫面(Home按鈕在屏幕上面),可省略768x1024或者768x1004

Default-LandscapeLeft.png?iPad專用橫向啟動(dòng)畫面,可省略1024x768或者1024x748

Default-LandscapeRight.png?iPad專用橫向啟動(dòng)畫面,可省略1024x768或者1024x748

Default.png?iPhone默認(rèn)啟動(dòng)圖片,如果沒有提供上面幾個(gè)iPad專用啟動(dòng)圖片,則在iPad上運(yùn)行時(shí)也使用Default.png(不推薦)320x480或者320x460

Default@2x.png?iPhone4啟動(dòng)圖片640x960或者640x920

為了在iPad上使用上述的啟動(dòng)畫面,你還需要在info.plist中加入key:?UISupportedInterfaceOrientations。同時(shí),加入值UIInterfaceOrientationPortrait,?UIInterfacOrientationPortraitUpsideDown,?UIInterfaceOrientationLandscapeLeft,?UIInterfaceOrientationLandscapeRight。

1.2延遲時(shí)間

2,如果想想設(shè)啟動(dòng)畫面的顯示時(shí)間,

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

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

[NSThread?sleepForTimeInterval:5.0];??//其實(shí)這一行代碼也可以不加,因?yàn)槟J(rèn)情況下歡迎界面的時(shí)間只有一秒,加這一句是為了延長

歡迎界面的展示時(shí)間到5秒,時(shí)間大家可以自己定義。

1.3啟動(dòng)時(shí)顯示狀態(tài)欄

?在-info.plist文件中加入選項(xiàng)"Status bar is initially

hidden",值為YES

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

*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法內(nèi)加入代碼:[[UIApplication sharedApplication] setStatusBarHidden:NO];

【注意】

如果你的程序同時(shí)使用了導(dǎo)航欄作為根視圖控制器UINavigationController,則應(yīng)該將語句[[UIApplication sharedApplication] setStatusBarHidden:NO]放在[self.window makeKeyAndVisible];之前,否則會(huì)出現(xiàn)狀態(tài)欄與導(dǎo)航欄重疊的情況??赡苁且?yàn)檎{(diào)用makeKeyAndVisible時(shí)會(huì)去判斷當(dāng)前程序是否顯示狀態(tài)欄,以此來布導(dǎo)航欄的位置。

2自定義方法

3,在XXXAppDelegate.m的-?(BOOL)application:(UIApplication?*)application?didFinishLaunchingWithOptions:(NSDictionary*)launchOptions中通過使用uiview或uiimageview等控件自定義啟動(dòng)畫面

3App圖標(biāo)添加

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

Solution:

icon 的大小注意長寬一樣,不然報(bào)錯(cuò):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的時(shí)候,通常不是直接進(jìn)入App主界面,而是會(huì)有一個(gè)能左右滑動(dòng)、介紹App功能的界面。我是用NSUserDefaults + UIScrollview實(shí)現(xiàn)。

新建一個(gè)類,繼承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];

}

這樣,就有了一個(gè)有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)閉水平方向上的滾動(dòng)條

scrollView.showsHorizontalScrollIndicator?=NO;

//是否可以整屏滑動(dòng)

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:@"開始體驗(yàn)"?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è)置未選中點(diǎn)的顏色

pageControl.pageIndicatorTintColor?=?[UIColor?whiteColor];

//設(shè)置選中點(diǎn)的顏色

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è)計(jì)思路

新建一個(gè)LaunchVC,然后在RootVC中以模態(tài)窗口的方式彈出此VC。引導(dǎo)頁采用本地緩存方式,支持從服務(wù)端動(dòng)態(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;

}

//動(dòng)態(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];

//取得一個(gè)目錄下得所有文件名

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一個(gè)窗口化的ViewController。但是這個(gè)窗口默認(rèn)的背景色是磨砂不透明的,因此還需要把它的背景色設(shè)為透明。這樣看起來就像是全屏遮罩一樣,但是由于系統(tǒng)不認(rèn)為新的View是全屏的,所以上一個(gè)View也不會(huì)被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實(shí)現(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];

建立一個(gè)view設(shè)置背景顏色調(diào)整alpha值

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

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

6參考鏈接

IOS啟動(dòng)頁面制作

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)頁實(shí)現(xiàn)(一)

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

iOS啟動(dòng)時(shí)如何添加引導(dǎo)頁面小demo

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

IOS閃屏制作——程序啟動(dòng)動(dòng)畫

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

ios實(shí)現(xiàn)引導(dǎo)頁面效果

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

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

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容