// GuideViewController.h
// Created by l.h on 14-5-6.
#import <UIKit/UIKit.h>
@interface GuideViewController : UIViewController<UIScrollViewDelegate>
@end
//
// GuideViewController.m
// Created by l.h on 14-5-6.
#import "GuideViewController.h"
#import "YHomeViewController.h"
#import "YCustomTabBarViewController.h"
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
@interface GuideViewController ()
@end
@implementation GuideViewController
{
UIPageControl *pageControl;
UIScrollView *dyScrollView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self initGuide]; //加载新用户指导页面
[self initpagecontrol];
}
-(void)initpagecontrol
{
pageControl = [[UIPageControl alloc] init];
pageControl.frame=CGRectMake(110, 400, 100, 30) ;
pageControl.numberOfPages = 4; // 一共显示多少个圆点(多少页)
// 设置非选中页的圆点颜色
pageControl.pageIndicatorTintColor = [UIColor redColor];
// 设置选中页的圆点颜色
pageControl.currentPageIndicatorTintColor = [UIColor blueColor];
// 禁止默认的点击功能
pageControl.enabled = NO;
pageControl.backgroundColor=[UIColor clearColor];
[self.view addSubview:pageControl];
}
-(void)initGuide
{
NSArray *IMGarray=@[@"1136yd.png",@"1136yd1.png",@"1136yd2.png",@"1136yd3.png"];
NSArray *IMGarray2=@[@"960yd.png",@"960yd1.png",@"960yd2.png",@"960yd3.png"];
dyScrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height)];
dyScrollView.delegate=self;
dyScrollView.backgroundColor=[UIColor greenColor];
dyScrollView.contentSize=CGSizeMake(320*[IMGarray count], 460);
dyScrollView.showsVerticalScrollIndicator=NO;
dyScrollView.pagingEnabled=YES;
dyScrollView.bounces=NO; //取消弹性
dyScrollView.showsHorizontalScrollIndicator=NO;
[self.view addSubview:dyScrollView];
for (int i=0; i<[IMGarray count]; i++)
{
UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(i*320, 0, 320, self.view.frame.size.height)];
imgView.image=[UIImage imageNamed:(iPhone5?[IMGarray objectAtIndex:i]:[IMGarray2 objectAtIndex:i])];
imgView.contentMode = UIViewContentModeScaleAspectFit;
// imgView.autoresizesSubviews = YES;
// imgView.autoresizingMask =
// UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[dyScrollView addSubview:imgView];
if (i==[IMGarray count]-1)
{
[imgView setUserInteractionEnabled:YES];
UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame=CGRectMake(110, 300, 100, 40);
[button setBackgroundImage:[UIImage imageNamed:@"ksty"] forState:UIControlStateNormal];
// [button setTitle:@"立即体验" forState:UIControlStateNormal];
[button addTarget:self action:@selector(firstpressed) forControlEvents:UIControlEventTouchUpInside];
[imgView addSubview:button];
}
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//更新UIPageControl的当前页
CGPoint offset = scrollView.contentOffset;
CGRect bounds = scrollView.frame;
[pageControl setCurrentPage:offset.x / bounds.size.width];
}
-(void) scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pageWidth = self.view.frame.size.width;
// 在滚动超过页面宽度的50%的时候,切换到新的页面
int page = floor((dyScrollView.contentOffset.x + pageWidth/2)/pageWidth) ;
pageControl.currentPage = page;
}
//点击button跳转到根视图
- (void)firstpressed
{
[self.view removeFromSuperview];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
-(void)viewWillDisappear:(BOOL)animated
{
self.view=nil;
}
@end
// YAppDelegate.m
#import "YAppDelegate.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self isFirstLuachtheApp];
}
////判断是不是第一次启动应用
-(void)isFirstLuachtheApp
{
//如果不是第一次启动的话,使用LoginViewController作为根视图
[self navigationController];
//判断是不是第一次启动应用 先覆盖根视图之后移除
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
NSLog(@"第一次启动");
//如果是第一次启动的话,使用UserGuideViewController (用户引导页面) 作为根视图
_gvc=[[GuideViewController alloc]init];;
[self.window addSubview:self.gvc.view];
}
}
-(void)navigationController
{
YHomeViewController *HomeVC = [[YHomeViewController alloc] init];
YJobSearchViewController *JobSearchVC = [[YJobSearchViewController alloc] init];
YMyLifeViewController *LifeVC = [[YMyLifeViewController alloc] init];
YChangeViewController *ChangeVC = [[YChangeViewController alloc] init];
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:HomeVC];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:JobSearchVC];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:LifeVC];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:ChangeVC];
NSArray *array = [NSArray arrayWithObjects:navController1,navController2,navController4,navController3,HomeVC,JobSearchVC,ChangeVC,LifeVC,nil];
YCustomTabBarViewController *tabBarViewController = [[YCustomTabBarViewController alloc] init];
tabBarViewController.viewControllers = array;
tabBarViewController.seletedIndex = 0;
self.window.rootViewController = tabBarViewController;
}