zoukankan      html  css  js  c++  java
  • 轮播

    -(void)scrollviewff{
       
        self.scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
       
         _scrollview.backgroundColor =[UIColor redColor];
       
        [self.view addSubview:_scrollview];
        _scrollview.contentSize=CGSizeMake(self.view.frame.size.width *4, 0);
       
        NSArray *imageArray= @[@"welcome1", @"welcome2",@"welcome3",@"welcome4"];
       
        for (int i=0; i<imageArray.count; i++) {
           
            UIImageView * imageView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:imageArray[i]]];
            imageView.frame =CGRectMake(i*_scrollview.frame.size.width, 0, _scrollview.frame.size.width, _scrollview.frame.size.height);
            //imageView.image=[UIImage imageNamed:imageArray[i]];
            [_scrollview addSubview:imageView];
        }
        _scrollview.pagingEnabled = YES;
        _scrollview.delegate=self;
     self.pagecontrol =[[UIPageControl alloc]initWithFrame:CGRectMake(_scrollview.center.x, 170, 60, 20)];
       self.pagecontrol.numberOfPages=imageArray.count;
    self.pagecontrol.currentPageIndicatorTintColor=[UIColor redColor];
     self.pagecontrol.pageIndicatorTintColor=[UIColor blackColor];
        //关闭分见用户
       //self.pagecontrol.userInteractionEnabled =NO;
      
         [self.view addSubview:self.pagecontrol];
     
        [self addTime];
    }
    -(void)addTime{
        self.time = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(pagecontroldd) userInfo:nil repeats:YES];
        [[NSRunLoop mainRunLoop] addTimer:self.time forMode:NSRunLoopCommonModes];
       
       
    }
    -(void)removetime{
        [self.time invalidate];
        self.time=nil;
       
    }
    -(void)pagecontroldd{
        NSInteger currenpage =self.pagecontrol.currentPage;
        currenpage ++;
        if (currenpage==4) {
              currenpage =0;
        }
        CGFloat with =self.scrollview.frame.size.width;
        CGPoint offset= CGPointMake(currenpage*with, 0.f);
        [UIView animateWithDuration:.2f animations:^{
            self.scrollview.contentOffset=offset;
        }];
        NSLog(@"dsadfas");
       
    }
    -(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
       
        [self removetime];
       
    }
    -(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
       
        [self addTime];
    }
    -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
      
        CGPoint point =scrollView.contentOffset;
        NSInteger integer =round(point.x/scrollView.frame.size.width);
       self.pagecontrol.currentPage =integer;
        

    一天一章
  • 相关阅读:
    《CMake实践》笔记二:INSTALL/CMAKE_INSTALL_PREFIX
    《CMake实践》笔记一:PROJECT/MESSAGE/ADD_EXECUTABLE
    《CMake实践》第三部分的示例代码的错误
    利用 autoconf 和 automake 生成 Makefile 文件
    如何安装 罗技“优联技术”无线鼠标、无线键盘?
    make 和 makefile 的关系
    编译器 cc、gcc、g++、CC 的区别
    如何撤销 PhpStorm/Clion 等 JetBrains 产品的 “Mark as Plain Text” 操作 ?
    Linux/Ubuntu tree 命令以树形结构显示文件夹目录结构
    C/C++ 静态链接库(.a) 与 动态链接库(.so)
  • 原文地址:https://www.cnblogs.com/hangman/p/5415133.html
Copyright © 2011-2022 走看看