码迷,mamicode.com
首页 > 其他好文 > 详细

第一次新特性

时间:2015-03-02 18:52:03      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

判断是否是第一次打开该版本
- (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

 

第一次新特性

标签:

原文地址:http://www.cnblogs.com/jsnan/p/4309023.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!