標籤:ios 源碼 新手引導
1.在Main.storyboard中找到,ScrollView和PageControl。2.在ScrollView中添加ImageView,新手引導頁有幾個圖片就添加幾個,然後設定ImageView的image,就是準備好的圖片。3.要設定好ScrollViewscroll View中的Left和View中的Width,使其等於圖片的大小,還有就是圖片大小的起始位置,第一張為(0,0),第二張的起始位置應該是(螢幕的寬度,0),以此類推。4.添加PageControl,這個的起始位置要手動的設定。5.設定同步//設定UIPageControl跟隨UIScrollView的變化而變化-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ _pc1.currentPage = scrollView.contentOffset.x / 424;}//要使UIScrollView跟隨UIPageControl變化的話,必須加監聽,要寫一個方法-(void)changeScrollView:(UIPageControl *)uip1{ [_sv1 setContentOffset:CGPointMake(424 * uip1.currentPage, 0) animated:YES];}源碼:#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UIScrollView *sv1;@property (weak, nonatomic) IBOutlet UIPageControl *pc1;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; //必須手動設定內容視圖的大小 _sv1.contentSize = CGSizeMake(424*3,736); //是否分頁 _sv1.pagingEnabled = YES; //滾動時是否顯示水平捲軸 _sv1.showsHorizontalScrollIndicator = NO; //滾動時是否顯示垂直捲軸 _sv1.showsVerticalScrollIndicator=NO; //為了設定UIPageControl,要用到代理方法判斷是否移動 _sv1.delegate = self; //要使UIScrollView跟隨UIPageControl變化的話,必須加監聽,要寫一個方法 [_pc1 addTarget:self action:@selector(changeScrollView:) forControlEvents: UIControlEventTouchUpInside];}//設定UIPageControl跟隨UIScrollView的變化而變化-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ _pc1.currentPage = scrollView.contentOffset.x / 424;}//要使UIScrollView跟隨UIPageControl變化的話,必須加監聽,要寫一個方法-(void)changeScrollView:(UIPageControl *)uip1{ [_sv1 setContentOffset:CGPointMake(424 * uip1.currentPage, 0) animated:YES];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
本文出自 “紅角羚羊” 部落格,請務必保留此出處http://2254359459.blog.51cto.com/10776102/1733929
IOSAPP之新手引導