IOS新手引導頁的實現,源碼。,ios新手引導源碼
1 /*1.在Main.storyboard中找到,ScrollView和PageControl並添加到ViewController中。
2 2.在ScrollView中添加ImageView,新手引導頁有幾個圖片就添加幾個,然後設置ImageView的image,就是准備好的圖片。
3 3.要設置好ScrollViewscroll View中的Left和View中的Width,使其等於圖片的大小,還有就是圖片大小的起始位置,第一張為(0,0),第二張的起始位置應該是(屏幕的寬度,0),以此類推。
4 4.添加PageControl,這個的起始位置要手動的設置。
5 5.設置同步*/
6 //設置UIPageControl跟隨UIScrollView的變化而變化
7 -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
8 _pc1.currentPage = scrollView.contentOffset.x / 424;
9 }
10 //要使UIScrollView跟隨UIPageControl變化的話,必須加監聽,要寫一個方法
11 -(void)changeScrollView:(UIPageControl *)uip1
12 {
13 [_sv1 setContentOffset:CGPointMake(424 * uip1.currentPage, 0) animated:YES];
14 }
15
16 源碼:
17
18 #import "ViewController.h"
19
20 @interface ViewController ()
21 @property (weak, nonatomic) IBOutlet UIScrollView *sv1;
22 @property (weak, nonatomic) IBOutlet UIPageControl *pc1;
23
24 @end
25
26 @implementation ViewController
27
28 - (void)viewDidLoad {
29 [super viewDidLoad];
30 //必須手動設置內容視圖的大小
31 _sv1.contentSize = CGSizeMake(424*3,736);
32 //是否分頁
33 _sv1.pagingEnabled = YES;
34 //滾動時是否顯示水平滾動條
35 _sv1.showsHorizontalScrollIndicator = NO;
36 //滾動時是否顯示垂直滾動條
37 _sv1.showsVerticalScrollIndicator=NO;
38 //為了設置UIPageControl,要用到代理方法判斷是否移動
39 _sv1.delegate = self;
40 //要使UIScrollView跟隨UIPageControl變化的話,必須加監聽,要寫一個方法
41 [_pc1 addTarget:self action:@selector(changeScrollView:) forControlEvents: UIControlEventTouchUpInside];
42 }
43 //設置UIPageControl跟隨UIScrollView的變化而變化
44 -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
45 _pc1.currentPage = scrollView.contentOffset.x / 424;
46 }
47 //要使UIScrollView跟隨UIPageControl變化的話,必須加監聽,要寫一個方法
48 -(void)changeScrollView:(UIPageControl *)uip1
49 {
50 [_sv1 setContentOffset:CGPointMake(424 * uip1.currentPage, 0) animated:YES];
51 }
52 - (void)didReceiveMemoryWarning {
53 [super didReceiveMemoryWarning];
54 // Dispose of any resources that can be recreated.
55 }
56
57 @end