美文网首页
2018-07-02

2018-07-02

作者: 朕i | 来源:发表于2018-07-02 08:10 被阅读0次

#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];

    }

}

相关文章

网友评论

      本文标题:2018-07-02

      本文链接:https://www.haomeiwen.com/subject/uwrkuftx.html