• 滚动视图UIScrollView


    int i;

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

       

      

        

        self.myScrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];

        self.myScrollV.backgroundColor = [UIColor whiteColor];

        self.myScrollV.contentSize = CGSizeMake(WIDTH * 4, HEIGHT / 4);

        self.myScrollV.delegate = self;

        [self.view addSubview:self.myScrollV];

        

        

        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT / 4)];

        imageV.image = [UIImage imageNamed:@"/Users/scjy/Desktop/UI代码/SecrolView/SecrolView/屏幕快照 2016-03-11 下午12.54.17.png"];

        [self.myScrollV addSubview:imageV];

        

        UIImageView *imageV1 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH , HEIGHT / 4)];

        imageV1.image = [UIImage imageNamed:@"/Users/scjy/Desktop/UI代码/SecrolView/SecrolView/屏幕快照 2016-03-11 下午12.54.27.png"];

        [self.myScrollV addSubview:imageV1];

        

        UIImageView *imageV3 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * 3, 0, WIDTH , HEIGHT / 4)];

        imageV3.image = [UIImage imageNamed:@"/Users/scjy/Desktop/UI代码/SecrolView/SecrolView/屏幕快照 2016-03-11 下午12.54.00.png"];

        [self.myScrollV addSubview:imageV3];

        

        UIImageView *imageV2 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * 2, 0, WIDTH, HEIGHT / 4)];

        imageV2.image = [UIImage imageNamed:@"/Users/scjy/Desktop/UI代码/SecrolView/SecrolView/屏幕快照 2016-03-11 下午12.55.26.png"];

        [self.view addSubview:imageV2];

        

        UIImageView *imageV4 = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * 4, 0, WIDTH, HEIGHT / 4)];

        imageV4.image = [UIImage imageNamed:@"/Users/scjy/Desktop/UI代码/SecrolView/SecrolView/屏幕快照 2016-03-11 下午2.29.19.png"];

        [self.view addSubview:imageV4];

        

        self.myScrollV.pagingEnabled = YES;

        //影藏滚动条

        self.myScrollV.showsHorizontalScrollIndicator = NO;

        self.myScrollV.directionalLockEnabled = YES;

        [self.myScrollV addSubview:imageV2];

       self.page = [[UIPageControl alloc] initWithFrame:CGRectMake(100, HEIGHT / 4 - 50, 200, 40)];

        self.page.backgroundColor = [UIColor clearColor];

        self.page.numberOfPages = 4;

        self.page.currentPage = 0;

        

        

        [self.view addSubview:self.page];

        

       

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView

    {

        

        

        if (scrollView.contentOffset.x >= 0 && scrollView.contentOffset.x <=  WIDTH * 3)

        {

             self.page.currentPage =(int)(scrollView.contentOffset.x / WIDTH);

        }

        

        else if (scrollView.contentOffset.x < 0)

        {

            scrollView.contentOffset = CGPointMake(WIDTH * 3, scrollView.contentOffset.y);

            self.page.currentPage = (scrollView.frame.size.width -WIDTH) / WIDTH;

        }

        

        else if (scrollView.contentOffset.x > 3 * WIDTH)

        {

            scrollView.contentOffset = CGPointMake(0, scrollView.contentOffset.y);

            self.page.currentPage = 0;

            

            

        }

        

    #define HEIGHT  self.view.frame.size.height

    #define WIDTH   self.view.frame.size.width

    @interface ViewController : UIViewController<UIScrollViewDelegate>

    @property (strong,nonatomic) UIScrollView *myScrollV;

    @property (strong,nonatomic) UIPageControl *page;

    @end

        

        

        

    }

  • 相关阅读:
    [转]解读Unity中的CG编写Shader系列4——unity中的圆角矩形shader
    [转]解读Unity中的CG编写Shader系列5——理论知识
    [转]解读Unity中的CG编写Shader系列3——表面剔除与剪裁模式
    [转]解读Unity中的CG编写Shader系列二
    [转]解读Unity中的CG编写Shader系列1——初识CG
    使用 GPU 加速计算
    [转] Draw Call未被批处理?告诉你在Unity 5.6中如何查找原因 [复制链接]
    程序员,如何从平庸走向理想?
    SDUT-2122_数据结构实验之链表七:单链表中重复元素的删除
    SDUT-2121_数据结构实验之链表六:有序链表的建立
  • 原文地址:https://www.cnblogs.com/wujie123/p/5267330.html
Copyright © 2020-2023  润新知