判斷版本號
// 創始字符串
NSString *path = [[NSBundle mainBundle] pathForResource:@"Info.plist" ofType:nil];
// 創建字典
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];
// 打印版本的key
NSLog(@"%@",[dic objectForKey:@"CFBundleVersion"]);
// 判斷
if ([[dic objectForKey:@"CFBundleVersion"] isEqualToString:[[NSUserDefaults standardUserDefaults] valueForKey:@"version"]]) {
// 版本號相同
// 進入主頁面
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
}else{
// 版本號不相同
// 進入引導頁
[[NSUserDefaults standardUserDefaults] setObject:[dic objectForKey:@"CFBundleVersion"] forKey:@"version"];
self.window.rootViewController = [[YinDaoYeViewController alloc] init];
}
引導頁界面
// 創建滾動視圖
_myScroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
_myScroll.delegate = self;
[self.view addSubview:_myScroll];
// 設置滾動范圍
_myScroll.contentSize = CGSizeMake(self.view.frame.size.width * 4, self.view.frame.size.height);
// 取消彈簧效果
_myScroll.bounces = NO;
// 取消水平滾動條
_myScroll.showsHorizontalScrollIndicator = NO;
// 設置翻頁滾動
_myScroll.pagingEnabled = YES;
// 圖片數組
_imgArr = @[@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg"];
// for 循環
for (int i = 0; i < _imgArr.count; i ++) {
// 圖片框
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height)];
imgView.image = [UIImage imageNamed:_imgArr[i]];
[_myScroll addSubview:imgView];
imgView.userInteractionEnabled = YES;
// 在最后一張圖片上加按鈕
if (i == _imgArr.count - 1) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake((self.view.frame.size.width - 100)/2, 600, 100, 30);
[btn setTitle:@"立即體驗" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize:18];
[btn addTarget:self action:@selector(didClick) forControlEvents:UIControlEventTouchUpInside];
[imgView addSubview:btn];
}
}
// 創建分頁控件
_page = [[UIPageControl alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 100)/2, 670, 100, 30)];
// 分頁控件的個數
_page.numberOfPages = _imgArr.count;
// 所有控件的顏色
_page.pageIndicatorTintColor = [UIColor blackColor];
// 當前控件的顏色
_page.currentPageIndicatorTintColor = [UIColor redColor];
// 將分頁控件添加到視圖上
[self.view addSubview:_page];
點擊方法
// 立即體驗按鈕
-(void)didClick
{
[self presentViewController:[[ViewController alloc] init] animated:YES completion:nil];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
_page.currentPage = _myScroll.contentOffset.x/self.view.frame.size.width;
}
// 定時器
NSTimer *time = [NSTimer scheduledTimerWithTimeInterval:3 repeats:YES block:^(NSTimer * _Nonnull timer) {
CGFloat offsetX = _myScroll.contentOffset.x;
// 視圖的動畫
[UIView animateWithDuration:0.3 animations:^{
if (offsetX == self.view.frame.size.width * 3) {
_myScroll.contentOffset = CGPointMake(0, 0);
}else{
_myScroll.contentOffset = CGPointMake(offsetX + self.view.frame.size.width, 0);
}
}];
}];
[time fire];