引导页实现ScrollView左右无缝滚动


- (void)setupNavigation {

    // 获取app当前版本

    NSString *version = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];

    NSString *oldVersion = [[NSUserDefaults standardUserDefaults] objectForKey:@"needNavigation"];

    

    // 第一次运行app或者不是最新版本

    if (oldVesion == nil || ![oldVesion isEqualToString:version]) {

        _navigationScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

        _navigationScrollView.delegate = self;

        _navigationScrollView.pagingEnabled = YES;

        _navigationScrollView.bounces = NO;

        _navigationScrollView.showsHorizontalScrollIndicator = NO;

        _navigationScrollView.contentSize = CGSizeMake(SCREEN_WIDTH * 5, SCREEN_HEIGHT);

        _navigationScrollView.contentOffset = CGPointMake(SCREEN_WIDTH, 0);

        [self.view addSubview:_navigationScrollView];

        

        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(20, SCREEN_HEIGHT - 60 , SCREEN_WIDTH40, 44)];

        [button setTitle:@"立即体验" forState:UIControlStateNormal];

        [button setTitle:@"立即体验" forState:UIControlStateHighlighted | UIControlStateSelected];

        [button setTitleColor:UIColorFromRGB(Navigation_BG_Color) forState:UIControlStateNormal];

        [button setTitleColor:UIColorFromRGB(Navigation_BG_Color) forState:UIControlStateHighlighted | UIControlStateSelected];

        button.titleLabel.font = [UIFont systemFontOfSize:20.0];

        [button addTarget:self action:@selector(joinLoginPage) forControlEvents:UIControlEventTouchUpInside];

        UIButton *otherButton = [[UIButton alloc] initWithFrame:CGRectMake(20, SCREEN_HEIGHT - 60 , SCREEN_WIDTH40, 44)];

        [otherButton setTitle:@"立即体验" forState:UIControlStateNormal];

        [otherButton setTitleColor:UIColorFromRGB(Navigation_BG_Color) forState:UIControlStateNormal];

        otherButton.titleLabel.font = [UIFont systemFontOfSize:20.0];

        

        for (int i = 0; i < 5; i++) {

            UIImageView *page = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

            if (i == 0) {

                page.image = [UIImage imageNamed:@"yindao3"];

            } else if (i == 4) {

                page.image = [UIImage imageNamed:@"yindao1"];

            } else {

                page.image = [UIImage imageNamed:[NSString stringWithFormat:@"yindao%d",i]];

            }

            [_navigationScrollView addSubview:page];

            

            if (i == 0) {

                [page addSubview:otherButton];

            }

            if (i == 3) {

                page.userInteractionEnabled = YES;

                [page addSubview:button];

            }

        }

        

        [[NSUserDefaults standardUserDefaults] setObject:version forKey:@"needNavigation"];

        [[NSUserDefaults standardUserDefaults] synchronize];

    } else {


    }

}


#pragma mark - scrollView delegate

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

    if(scrollView == _navigationScrollView ) {

        // 实现左右无缝滚动

        int page = floor((_navigationScrollView.contentOffset.x - SCREEN_WIDTH / 2) / SCREEN_WIDTH) + 1;

        if (page == 0) {

            [_navigationScrollView scrollRectToVisible:CGRectMake(3 * SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT) animated:NO];

        } else if (page == 4) {

            [_navigationScrollView scrollRectToVisible:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT) animated:NO];

        }

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值