您的位置:首页 > 移动开发

iOS(二)App第一次启动时出现的引导界面

2015-11-17 15:47 946 查看
我们每次打开一个刚刚从AppStore下载下来的软件时,总会出来一个引导界面,有的是宣传产品,有的是介绍App的功能,最后再出来一个按钮正式进入到App,从此以后这个引导界面就再也不会出现了,除非你卸载重装,
在查阅相关资料后,做了个简陋的引导界面,一般的引导界面都是滑动了三四张图片后,出现一个进入的按钮,所以这里用到了ScrollView,



给ScrollView开启翻页,就可以做到视图滑动了,


在ScrollView添加三个ImageView,设置它们的坐标和大小,例如屏幕大小是320x568,三个ImageView大小都设置成320x568.坐标分别设置成,(0,0),(320,0),(640,0),并且添加image



添加三个文件

GuideViewController.h

#import <UIKit/UIKit.h>

@interface GuideViewController :UIViewController<UIScrollViewDelegate>

@property(weak,nonatomic)IBOutletUIButton
*gotoMainViewBtn;

-(IBAction)gotoMainViewBtn:(id)sender;

@property(weak,nonatomic)IBOutletUIScrollView
*pageScroll;

@property(weak,nonatomic)IBOutletUIPageControl
*pageControl;

@property(nonatomic,strong)UIImageView *left;

@property(nonatomic,strong)UIImageView *right;

@end

GuideViewController.m

#import "GuideViewController.h"

#import "ViewController.h"

@interfaceGuideViewController()

@end

@implementation GuideViewController

-(void)viewDidLoad{

[superviewDidLoad];

_pageControl.numberOfPages=3;

_pageControl.currentPage=0;

_pageScroll.delegate=self;

_pageScroll.contentSize=CGSizeMake(self.view.frame.size.width*3,self.view.frame.size.height);

_gotoMainViewBtn.frame=CGRectMake(self.view.frame.size.width*2+100,400,
100,
20);

}

-(IBAction)gotoMainViewBtn:(id)sender{

[[NSUserDefaultsstandardUserDefaults]setBool:NOforKey:@"firstLaunch"];

ViewController *controller=[[ViewControlleralloc]init];

[selfpresentViewController:controller
animated:YEScompletion:^(void){}];

}

//ScrollView代理

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

CGFloat pageWidth =self.view.frame.size.width;

int page =
floor((scrollView.contentOffset.x - pageWidth /2) / pageWidth) +
1;

_pageControl.currentPage = page;

}

@end

GuideViewController.xib



这里需要注意两点,

一:点击File's Owner,将Class改成GuideViewController



二:右击GuideViewController.xib里面的View出现Referencing Outlets,从New Referencing Outlets那里拖一根线拖到File‘s Owner

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

// Override point for customization after application launch.

self.window=[[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

[self.windowmakeKeyAndVisible];

if (![[NSUserDefaultsstandardUserDefaults]boolForKey:@"everLaunched"])
{

[[NSUserDefaultsstandardUserDefaults]
setBool:YESforKey:@"everLaunched"];

[[NSUserDefaultsstandardUserDefaults]
setBool:YESforKey:@"firstLaunch"];

}

if ([[NSUserDefaultsstandardUserDefaults]boolForKey:@"firstLaunch"])
{

self.window.rootViewController=[[GuideViewControlleralloc]
init];

} else {

self.window.rootViewController = [[ViewControlleralloc]
init];

}

returnYES;

}

第一次启动







主界面



第二次启动



下一篇 苹果自带的tabbar /article/9297480.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: