iOS 引导页
时间:2014-05-08 18:17:49
收藏:0
阅读:640
1
2
3
4 |
// GuideViewController.h // Created by l.h on 14-5-6.<br><br>#import <UIKit/UIKit.h><br>@interface GuideViewController : UIViewController<UIScrollViewDelegate> @end |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115 |
// // GuideViewController.m // Created by l.h on 14-5-6. <br>#import "GuideViewController.h" #import "YHomeViewController.h" #import "YCustomTabBarViewController.h" #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) <br> @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; }
评论(0)