- (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_WIDTH - 40, 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_WIDTH - 40, 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];
}
}
}