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++;
    }
  • 相关阅读:
    在现有项目中使用AspNet Identity 2.0 实战
    SQL 带自增长列的表的插入
    在C++中子类继承和调用父类的构造函数方法
    C++继承
    C++中重载、重写(覆盖)和隐藏的区别实例分析
    C++类
    C++中头文件(.h)和源文件(.cpp)都应该写些什么
    C++模板
    C语言字符串操作总结大全
    C++ 标准模板库(STL)
  • 原文地址:https://www.cnblogs.com/gcb999/p/3239893.html
Copyright © 2011-2022 走看看