• 照片浏览滑动效果UIScrollView和UIPageControl组合


    - (void)changePage:(UIPageControl *)pageControl{
    
        [_scrollView setContentOffset:CGPointMake(pageControl.currentPage*ScreenWidth, 0) animated:YES];
    }
    
    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
     
        _pageControl.currentPage = _scrollView.contentOffset.x/320;
    }

    上面是主要的代码。

    初始化uiscrolview 和 pagecontrol

    _mPictureArray = [NSMutableArray array];
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.delegate = self;
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.contentSize = CGSizeMake(ScreenWidth*3,0);
        _scrollView.pagingEnabled = YES;
        
        [self.view addSubview:_scrollView];
        [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
        }];
        
        for(int i=0;i<3;i++){
         
            UIImageView *contentImageView = [[UIImageView alloc] init];
            contentImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]];
            [_scrollView addSubview:contentImageView];
            [contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.with.equalTo(self.view);
                make.height.with.equalTo(self.view);
                make.left.equalTo(_scrollView).with.offset(ScreenWidth*i);
            }];
            [_mPictureArray addObject:contentImageView];
        }
        
        _pageControl = [[UIPageControl alloc] init];
        _pageControl.numberOfPages = 3;
        _pageControl.currentPage = 0;
        _pageControl.pageIndicatorTintColor = [UIColor redColor];
        [_pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_pageControl];
        [_pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(self.view);
            make.centerX.equalTo(self.view);
            make.top.equalTo(self.view).with.offset(ScreenHeight-50);
            make.height.offset(30);
        }];
  • 相关阅读:
    java.io.IOException: HTTPS hostname wrong: should be 规格严格
    linux syslog 规格严格
    SVN,HG,GIT 命令说明 规格严格
    pclose : no child process 规格严格
    使用NetBeans6开发OSGi应用(1)——FirstOSGi[88250原创]
    Netbeans大战Eclipse 谁将走向祭坛?
    XP中的重要惯例和规则
    使用NetBeans6开发OSGi应用(1)——FirstOSGi[88250原创]
    简简单单删除所有.svn目录
    简简单单删除所有.svn目录
  • 原文地址:https://www.cnblogs.com/machealking/p/5116736.html
Copyright © 2020-2023  润新知