zoukankan      html  css  js  c++  java
  • iOS新手引导页的实现,源码。

     1 /*1.在Main.storyboard中找到,ScrollView和PageControl并添加到ViewController中。
     2 2.在ScrollView中添加ImageView,新手引导页有几个图片就添加几个,然后设置ImageView的image,就是准备好的图片。
     3 3.要设置好ScrollViewscroll View中的Left和View中的Width,使其等于图片的大小,还有就是图片大小的起始位置,第一张为(00),第二张的起始位置应该是(屏幕的宽度,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
  • 相关阅读:
    python 字典
    python 列表
    被闭包啪啪啪的打脸之 闭包的错误使用
    TCP的三次握手和四次挥手
    传输层的TCP和UDP协议
    个人小程序应用开发指南
    ES2019 / ES10有什么新功能?
    CSS开启硬件加速来提高网站性能
    js中this的指向问题
    Js面向对象构造函数继承
  • 原文地址:https://www.cnblogs.com/BK-12345/p/5122395.html
Copyright © 2011-2022 走看看