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
在查阅相关资料后,做了个简陋的引导界面,一般的引导界面都是滑动了三四张图片后,出现一个进入的按钮,所以这里用到了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
相关文章推荐
- Android 开发 常见错误
- Android从服务器获取图片的实例方法
- 使用BIOS中断和汉字库显示汉字
- iOS 公司开发者账号申请
- Android EventBus源码解析 带你深入理解EventBus
- Objective-C中NSArray和NSMutableArray的基本用法
- Android——生成签名APK
- iOS开发内购全套图文教程
- iOS:JSON格式字符串转字典,字典转JSON格式字符串
- Swift自学_数据类型
- 微信公众号与HTML 5混合模式揭秘2——分享手机相册中照片
- 一个android文本比对app的实现(二)--界面
- Write your own Android Authenticator (Account Manager)
- Android中常用的位图操作(View与Bitmap转化、圆角、灰化、提取Alpha、旋转、倒影、剪切……)
- ios:从系统相册选取视频并获得视频的缩略图
- Service的整理,持续更新
- 微信公众号与HTML 5混合模式揭秘1——如何部署JSSDK
- android hal学习——测试整个流程
- App - 版本控制
- Qt学习之路(10): Meta-Object系统