我的解决方案:...
1、在appdelegate.m中找到
“application:didFinishLaunchingWithOptions:”方法, 添加以下代码:
/**
* 前导页
*/
if([[[NSUserDefaults standardUserDefaults] objectForKey:@"isExisted"]isEqualToString:@"exist"]){
[self gotoMain];
NSLog(@"222222222");
}else{
FirstLaunchViewController *firstLaunchVC = [[FirstLaunchViewController alloc]init];
self.window.rootViewController = firstLaunchVC;
NSLog(@"111111111");
}
-(void)gotoMain
{
NSLog(@"主页。。。");
[[NSUserDefaults standardUserDefaults] setObject:@"exist" forKey:@"isExisted"];
MainViewController *firstLaunchVC = [[MainViewController alloc]init];
self.window.rootViewController = firstLaunchVC;
NSLog(@"111111111");
}
总的解决办法是 key: @”isExisted” 对应的value 是不是“exist”判断用户以前是否登录,
在第一次启动的时候 key @” isExisted” 不会被赋址的, 也就是说value为nil.
2、前导页
新建FirstLaunchViewController文件,走完前导页,调用的APPDelegate.h方法进入主页界面。。。
#import "JYEFirstLaunchViewController.h"
#import "AppDelegate.h"
@interface FirstLaunchViewController ()<UIScrollViewDelegate>
{
UIPageControl * pageCtr;
BOOL isOut;//判断是否进入主页
}
@end
@implementation JYEFirstLaunchViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self gotoLaunchView];
}
-(void)gotoLaunchView
{
NSLog(@"引导页");
UIScrollView * scroll = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
scroll.pagingEnabled = YES;
scroll.delegate = self;
scroll.contentOffset = CGPointMake(0, 0);
scroll.contentSize = CGSizeMake(self.view.frame.size.width * 3, self.view.frame.size.height);
// scroll.bounces = NO;//让scrollView在他的自身范围内滑动//在这里添加“进入应用Button”
[self.view addSubview:scroll];
NSArray * imageArr = @[@"[email protected]",@"[email protected]",@"[email protected]"];
for(int i = 0;i<imageArr.count;i++)
{
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height)];
imageView.image = [UIImage imageNamed:imageArr[i]];
[scroll addSubview:imageView];
}
pageCtr = [[UIPageControl alloc]initWithFrame:CGRectMake(50, scroll.frame.size.height - 30, scroll.frame.size.width - 100, 30)];
pageCtr.currentPage = 0;
pageCtr.numberOfPages = imageArr.count;
pageCtr.pageIndicatorTintColor = [UIColor redColor];
[self.view addSubview:pageCtr];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scrollView.contentOffset.x > self.view.frame.size.width * 2)
{
//跳到主界面
isOut = YES;
}
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
pageCtr.currentPage = scrollView.contentOffset.x / self.view.frame.size.width;
if(isOut)
{
[UIView animateWithDuration:0.1 animations:^{
scrollView.alpha = 0;
} completion:^(BOOL finished) {
[scrollView removeFromSuperview];
[self gotoMain1];
}];
}
}
-(void)gotoMain1{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate gotoMain];
NSLog(@"zhuye");
}