2018-07-02

#import "MainViewController.h"

@interface ViewController ()

{

    NSArray*imgArr;

    UIScrollView *scv;

    UIPageControl *page;


    NSTimer*timer;

    intk;

}

@end

@implementation ViewController

- (void)viewDidLoad

{

    [super viewDidLoad];


    timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(change) userInfo:nil repeats:YES];


    imgArr = @[@"man1",@"man2",@"man3",@"man4"];


    //新特性界面

    //滚动视图

    scv = [[UIScrollView alloc]initWithFrame:self.view.frame];

    //上颜色

    scv.backgroundColor = [UIColor purpleColor];


    //设置滚动范围

    scv.contentSize = CGSizeMake(self.view.frame.size.width *4, self.view.frame.size.height);

    //初始化图片

    for(inti=0; i<4; i++)

    {


        UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(i*self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];


        //设置分页

        scv.pagingEnabled = YES;


        //隐藏水平滚动条

        scv.showsHorizontalScrollIndicator = NO;


        //取消弹簧效果

        scv.bounces=NO;


        //设置滚动视图的代理

        scv.delegate=self;


        //设置图片

        imgV.image= [UIImageimageNamed:imgArr[i]];


        [scvaddSubview:imgV];

    }


    [self.view addSubview:scv];

}

-(void)scrollViewDidScroll:(UIScrollView*)scrollView

{

    page.currentPage = scv.contentOffset.x/self.view.frame.size.width;

    NSLog(@"%lf",scv.contentOffset.x);

}

-(void)change

{

    k = scv.contentOffset.x/self.view.frame.size.width;

    k++;


    scv.contentOffset = CGPointMake(k *self.view.frame.size.width, 0);


    if(k>=3)

    {

        [timerinvalidate];


        MainViewController * MainVc = [[MainViewController alloc]init];

        //跳转下一个界面

        [self presentViewController:MainVc animated:YES completion:nil];

    }


}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容