判断是否是第一次打开该版本 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { application.statusBarHidden = NO; // 1.创建窗口 self.window = [[UIWindow alloc] init]; self.window.frame = [UIScreen mainScreen].bounds; // 2.设置窗口的根控制器 // 如何知道第一次使用这个版本?比较上次的使用情况 //NSString *versionKey = @"CFBundleVersion"; NSString *versionKey = (__bridge NSString *)kCFBundleVersionKey; // 从沙盒中取出上次存储的软件版本号(取出用户上次的使用记录) NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *lastVersion = [defaults objectForKey:versionKey]; // 获得当前打开软件的版本号 NSString *currentVersion = [NSBundle mainBundle].infoDictionary[versionKey]; if ([currentVersion isEqualToString:lastVersion]) { // 当前版本号 == 上次使用的版本:显示HMTabBarViewController self.window.rootViewController = [[SNTabBarViewController alloc] init]; } else { // 当前版本号 != 上次使用的版本:显示版本新特性 self.window.rootViewController = [[SNNewfeatureViewController alloc] init]; // 存储这次使用的软件版本 [defaults setObject:currentVersion forKey:versionKey]; [defaults synchronize]; } // 3.显示窗口(成为主窗口) [self.window makeKeyAndVisible]; return YES; }
现实新特性#define SNNewfeatureImageCount 4 #import "SNNewfeatureViewController.h" @interface SNNewfeatureViewController () <UIScrollViewDelegate> @property (nonatomic, weak)UIPageControl *pageControl; @end @implementation SNNewfeatureViewController - (void)viewDidLoad { [super viewDidLoad]; //1.添加UISrollView [self setupScrollView]; //2.添加pageControl [self setupPageControl]; } -(void)setupScrollView { //1.添加UISrollView UIScrollView *scrollView = [[UIScrollView alloc]init]; scrollView.frame = self.view.bounds; scrollView.delegate = self; [self.view addSubview:scrollView]; //2.添加图片 CGFloat imageW = scrollView.width; CGFloat imageH = scrollView.height; for (int i = 0; i<SNNewfeatureImageCount; i++) { //图片 UIImageView *imageView = [[UIImageView alloc]init]; NSString *name = [NSString stringWithFormat:@"new_feature_%d", i+1]; if (FourInch) { name = [name stringByAppendingString:@"-568h"]; } imageView.image = [UIImage imageNamed:name]; [scrollView addSubview:imageView]; //设置frame imageView.y = 0; imageView.width = imageW; imageView.height = imageH; imageView.x = i * imageW; //给最后一个imageView添加按钮 } //3.设置其他属性 //总长度 scrollView.contentSize = CGSizeMake(imageW * SNNewfeatureImageCount, 0); //要么不切换,要么切换一屏 scrollView.pagingEnabled = YES; //隐藏滚动条 scrollView.showsHorizontalScrollIndicator = NO; //没有回弹效果 //scrollView.bounces = NO; //回弹,背景色 scrollView.backgroundColor = SNColor(246, 246, 246); } -(void)setupPageControl { //1.添加 UIPageControl *pageControl = [[UIPageControl alloc]init]; pageControl.numberOfPages = SNNewfeatureImageCount; pageControl.centerX = self.view.width * 0.5; pageControl.centerY = self.view.height - 30; [self.view addSubview:pageControl]; //2.设置圆点颜色 pageControl.currentPageIndicatorTintColor = SNColor(253, 98, 42); pageControl.pageIndicatorTintColor = SNColor(189, 189, 189); self.pageControl = pageControl; } #pragma mark - UIScrollViewDelegate -(void)scrollViewDidScroll:(UIScrollView *)scrollView { //获得页码 CGFloat doublePage = scrollView.contentOffset.x / scrollView.width; int intPage = (int)(doublePage + 0.5); //设置页码 self.pageControl.currentPage = intPage; } @end
时间: 2024-11-08 20:30:10