摘要: IOS引导页
#import "AppDelegate.h"
//引导页
#import "GuidePageViewController.h"
//tabbar控制器
#import "GPTabBarViewController.h"
@interface AppDelegate ()
@property(nonatomic,assign) BOOL isExist;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"YINDAOYE"] isEqualToString:@"YINDAOYE"]){//归档标记存在,直接进入主页面
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UIStoryboard *storyboard= [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
GPTabBarViewController *gpVC=[storyboard instantiateViewControllerWithIdentifier:@"GPTabBarViewController"];
self.window.backgroundColor=[UIColor whiteColor];
self.window.rootViewController=gpVC;
[self.window makeKeyAndVisible];
//删除归档
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"YINDAOYE"];
}else{//归档标记不存在,归档标记后,进入进入引导页
[[NSUserDefaults standardUserDefaults] setObject:@"YINDAOYE" forKey:@"YINDAOYE"];
GuidePageViewController *guidePageVC=[[GuidePageViewController alloc]init];
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor=[UIColor whiteColor];
self.window.rootViewController=guidePageVC;
[self.window makeKeyAndVisible];
}
return YES;
}
#import "GuidePageViewController.h"
#import "GPTabBarViewController.h"
@interface GuidePageViewController ()<UIScrollViewDelegate>
@end
@implementation GuidePageViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self guldePage];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
-(void)buttonClick:(UIButton *)button{
UIStoryboard *storyboard= [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
GPTabBarViewController *gpVC=[storyboard instantiateViewControllerWithIdentifier:@"GPTabBarViewController"];
UIWindow *window=[UIApplication sharedApplication].keyWindow;
window.rootViewController=gpVC;
}
-(void)guldePage{
NSArray *imgArray=@[[UIImage imageNamed:@"w1.jpg"],[UIImage imageNamed:@"w2.jpg"],[UIImage imageNamed:@"w3.jpg"]];
UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:self.view.bounds];
scrollView.tag=200;
scrollView.pagingEnabled=YES;
scrollView.showsHorizontalScrollIndicator=NO;
scrollView.showsVerticalScrollIndicator=NO;
scrollView.delegate=self;
scrollView.contentSize=CGSizeMake(scrollView.bounds.size.width*3, scrollView.bounds.size.height);
for (int i =0; i <3; i++) {
UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(i*scrollView.bounds.size.width, 0, scrollView.bounds.size.width, scrollView.bounds.size.height)];
imageView.image=imgArray[i];
[scrollView addSubview:imageView];
if(i==2){
imageView.userInteractionEnabled=YES;
UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake((imageView.bounds.size.width-150)/2 , imageView.bounds.size.height-60, 150, 50)];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitle:@"点击进入" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
button.layer.masksToBounds=YES;
button.layer.cornerRadius=25.0;
button.backgroundColor=[UIColor redColor];
[imageView addSubview:button];
}
}
[self.view addSubview:scrollView];
UIPageControl *pageC=[[UIPageControl alloc]initWithFrame:CGRectMake((self.view.bounds.size.width-80)/2, self.view.bounds.size.height-30-60, 80, 30)];
pageC.tag=201;
pageC.numberOfPages=3.0;
[self.view addSubview:pageC];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSInteger index=scrollView.contentOffset.x/scrollView.bounds.size.width;
UIPageControl *pageC=(UIPageControl *)[self.view viewWithTag:201];
pageC.currentPage=index;
}
© 著作权归作者所有