iOS新手引导页的实现,源码

来源:互联网 发布:linux 局域网 编辑:程序博客网 时间:2024/05/22 01:37
1.在Main.storyboard中找到,ScrollView和PageControl并添加到ViewController中。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


0 0
原创粉丝点击