zoukankan      html  css  js  c++  java
  • ios中滚动页面

    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            int width=frame.size.width;
            int height=frame.size.height;
            scrollview=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
            [self addSubview:scrollview];
            for (int i=0; i<3; i++) {
                UIImageView *imageview=[[UIImageView alloc] initWithFrame:CGRectMake(i*width, 0, width, height)];
                imageview.image=[UIImage imageNamed:[NSString stringWithFormat:@"image%zi@2x.jpg",(i+1)]];
                [scrollview addSubview:imageview];
            }
            scrollview.contentSize=CGSizeMake(3*width, height);
            scrollview.pagingEnabled=YES;
            scrollview.showsVerticalScrollIndicator=NO;
            scrollview.showsHorizontalScrollIndicator=NO;
            scrollview.delegate=self;
            scrollview.bounces=NO;
            
            pagecontroller=[[UIPageControl alloc] initWithFrame:CGRectMake((width-200)*0.5f, height-50-10, 200, 50)];
            [self addSubview:pagecontroller];
            
            pagecontroller.currentPage=0;
            pagecontroller.numberOfPages=3;
            currentPage=0;
    
           self.timer=[NSTimer scheduledTimerWithTimeInterval:5 target:self
                                                     selector:@selector(timer:) userInfo:nil repeats:YES];
            [self.timer fire];
            
        }
        return self;
    }
    
    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        CGFloat width=self.bounds.size.width;
        CGPoint point=scrollview.contentOffset;
        CGFloat offenx=point.x;
        pagecontroller.currentPage=offenx/width;
    }
    
    
    -(void)timer:(NSTimer *)time{
        if (currentPage>2) {
            currentPage=0;
        }
        CGFloat width=self.bounds.size.width;
        [UIView beginAnimations:nil context:nil];
        scrollview.contentOffset=CGPointMake(currentPage*width, 0);
        pagecontroller.currentPage=currentPage;
        [UIView commitAnimations];
        currentPage++;
    }
  • 相关阅读:
    2016.10.15先占坑
    2016.10.11先占坑
    2016.10.13先占坑
    2016.10.7先占坑
    main()里面为什么要放String[] args
    对于一个给定的正整数 n ,请你找出一共有多少种方式使 n 表示为若干个连续正整数的和,要求至少包括两个正整数。
    求两个数的最大公约数的三种算法总结
    C++
    Dev-c5.11的使用
    客户端和服务器端的交互(未完待续)
  • 原文地址:https://www.cnblogs.com/gcb999/p/3239893.html
Copyright © 2011-2022 走看看