//本地缓存的版本号 第一次启动的时候本地是没有缓存版本号的。
NSString *versionCache = [[NSUserDefaults standardUserDefaults] objectForKey:@"VersionCache"];
//当前应用版本号
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//如果本地缓存的版本号和当前应用版本号不一样,则是第一次启动(更新版本也算第一次启动)
if (version == nil || ![versionCache isEqualToString:version])
{
MSUTabbarController *tab = [[MSUTabbarController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:tab];
nav.navigationBar.hidden = YES;
self.window.rootViewController = nav;
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
_scrollView.backgroundColor = [UIColor orangeColor];
_scrollView.pagingEnabled = YES;
_scrollView.delegate = self;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.contentSize = CGSizeMake(WIDTH * 3, HEIGHT);
[self.window addSubview:_scrollView];
[self.window bringSubviewToFront:_scrollView];
//启动页的滑动页面
NSArray *picArray = [[NSArray alloc] initWithObjects:@"yindaoye1", @"yindaoye2",@"yindaoye3",nil];
for (int i = 0; i < picArray.count; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, HEIGHT)];
imageView.image = [MSUPathTools showImageWithContentOfFileByName:[picArray objectAtIndex:i]];
[_scrollView addSubview:imageView];
}
//设置上下面这句话,将当前版本缓存到本地,下次对比一样,就不走启动视屏了。
//也可以将这句话放在MSUMovieController.m的进入应用方法enterMainAction里面
//为了让每次都可以看到启动视屏,这句话先注释掉
// [[NSUserDefaults standardUserDefaults] setObject:version forKey:@"VersionCache"];
// [[NSUserDefaults standardUserDefaults] synchronize];
}else{
//不是首次启动
[self createRootWithDictionary:launchOptions application:(UIApplication *)application];
}
pragma mark - 隐藏引导页
-
(void)hideGuidView{
[UIView animateWithDuration:0.5 animations:^{
_scrollView.alpha = 0;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[_scrollView removeFromSuperview];});
}];
}
pragma mark - scrollView Delegate
- (void)scrollViewWillBeginDragging:(UIScrollView )scrollView{
int cuttentIndex = (int)(scrollView.contentOffset.x + kScreen_width0.5)/kScreen_width;
BOOL isScrollOut = YES;
if (cuttentIndex == 2) {
if ([self isScrolltoLeft:scrollView]) {
if (!isScrollOut) {
return;
}
[self hideGuidView];
}
}
}
pragma mark - 判断滚动方向
- (BOOL )isScrolltoLeft:(UIScrollView *)scrollView{
//返回YES为向左滑动,NO为右滚动
if ([scrollView.panGestureRecognizer translationInView:scrollView.superview].x < 0) {
NSLog(@"%f",[scrollView.panGestureRecognizer translationInView:scrollView.superview].x);
return YES;
}else{
return NO;
}
}
网友评论