zoukankan      html  css  js  c++  java
  • UIScrollView 图片循环滚动

    1:假如有6个图片:那个,Scrollview的大小加 7 个图片的大小

    2:

      //ImageScrollView;
        UIScrollView *imageScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 210)];
        imageScroll.bounces = YES;
        imageScroll.pagingEnabled = YES;
        imageScroll.userInteractionEnabled = YES;
        imageScroll.showsVerticalScrollIndicator = NO;
        imageScroll.showsHorizontalScrollIndicator = NO;
        imageScroll.delegate = self;
        imageScroll.contentSize = CGSizeMake(320 * 7, 210);
        [theScrollView addSubview:imageScroll];
        [imageScroll release];
        
        //加上图片;
        for (int i = 0; i < 7; i++) {
            UIImageView *aImageView = [[UIImageView alloc]initWithFrame:kCR(0 + 320*i, 0, 320, 210)];
            aImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"keenLC%d.jpg",i+1]];
            if (i==6) {
                aImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"keenLC%d.jpg",1]];
            }
    
            
            [imageScroll addSubview:aImageView];
            [aImageView release];
            
        }
        //图片数字label
        imageNumLabel = [[UILabel alloc]initWithFrame:kCR(130, imageScroll.bottom - 27, 60, 25)];
        imageNumLabel.text = @"1/6";
        imageNumLabel.textAlignment = NSTextAlignmentCenter;
        imageNumLabel.textColor = [UIColor whiteColor];
        imageNumLabel.backgroundColor = [UIColor clearColor];
        [theScrollView addSubview:imageNumLabel];
        [imageNumLabel release];

    3: ScrollView的代理

    #pragma mark Scroll delegate
    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;{
        int currentPage = floor((scrollView.contentOffset.x - scrollView.frame.size.width / 2) /  scrollView.frame.size.width) + 1;
        imageNumLabel.text = [NSString stringWithFormat:@"%d/6",currentPage + 1];
        //imageScroll.transform = CGAffineTransformMakeScale(1,1);
        if (currentPage==6) {
            [scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
            imageNumLabel.text = [NSString stringWithFormat:@"%d/6",1];
        }
    }
  • 相关阅读:
    android问题及其解决-优化listView卡顿和怎样禁用ListView的fling
    平安科技移动开发二队技术周报(第三期)
    机房重构(个人版)——类图
    php-wamp环境搭建
    ajax 通过return 返回data值
    cocos2d-x中六种持续性动作
    Android SimpleAdapter
    jquery 判断当前上传文件大小限制上传格式 搭配thinkphp实现上传即预览(模拟异步上传)
    【转】我的第一个Python小程序
    python官网
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3250160.html
Copyright © 2011-2022 走看看