iOS版本首次启动新特性实现总结

一、新特性界面简介:

iOS中几乎所有的软件在我们第一次安装后打开或者版本跟新时都会再启动时显示几幅图片来介绍新版本的特性。那么,今天就来介绍一下如何实现这种新特性的效果。

二、实现效果如下:


三、是否显示新特性界面的思路和实现。

a)取出Info.plist文件中得版本号
<span style="font-weight: normal;"><span style="font-size:12px;"><span style="white-space:pre">	</span>NSString *versionKey =  (NSString *)kCFBundleVersionKey;
	//说明:在CoreFoundation框架的CFBundle.h头文件中定义了一些宏,是Info.plist文件(字典)中保存的属性的key值。
	NSString *version =  [NSBundle mainBundle].infoDictionary[versionKey];
	//说明:NSBundle类中有一个实力方法读取Info.plist文件,保存到一个字典中。</span></span>

b)从沙盒中取出记录的版本号

<span style="font-size:12px;"><span style="white-space:pre">	</span>NSString *saveVersion = [[NSUserDefaults standardUserDefaults] objectForKey:versionKey];
<span style="white-space:pre">	</span>//说明:从偏好设置中取出保存的版本号。第一次使用应用程序取出为空,如何保存请参照d)步骤。</span>

c)两个版本号是否相同,不相同则显示新特性界面,相同则跳入主界面。

<span style="font-size:12px;"><span style="white-space: pre;">	</span>if ([version isEqualToString:saveVersion]) {
	// 并非第一次使用此版本,跳入主界面
		self.window.rootViewController = [[MainViewController alloc] init];
	} else {
		// 第一次使用此版本,跳入新特性界面
		d)将版本信息写入沙盒。
		[[NSUserDefaults standardUserDefaults] setObject:version forKey:versionKey];
        	[[NSUserDefaults standardUserDefaults] synchronize];
		//新特性显示
		self.window.rootViewController = [[NewFeatureViewController alloc] init];
	}</span>

四、新特性控制器的设计思路和实现。

1、上图所展示的页面中可以左右滑动,主界面是UIScrollView,下面有一个显示当前页码的为UIPageControl。
 
<span style="font-size:12px;">#define kCount 4

@interface NewfeatureController () <UIScrollViewDelegate>
{
    UIPageControl *_page;
    UIScrollView *_scroll;
}
@end

@implementation NewfeatureController

#pragma mark 自定义view
- (void)loadView
{
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage fullscrennImage:@"new_feature_background.png"];
    
    imageView.frame = [UIScreen mainScreen].applicationFrame;
    // 设置控件可以和用户交互(这样才能接受触摸事件)。
    imageView.userInteractionEnabled = YES;
    self.view = imageView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 1.添加UIScrollView
    [self addScrollView];
    
    // 2.添加图片
    [self addScrollImages];
    
    // 3.添加UIPageControl
    [self addPageControl];
}

#pragma mark - UI界面初始化
#pragma mark 添加滚动视图
- (void)addScrollView
{
    UIScrollView *scroll = [[UIScrollView alloc] init];
    scroll.frame = self.view.bounds;
    scroll.showsHorizontalScrollIndicator = NO; // 隐藏水平滚动条
    CGSize size = scroll.frame.size;
    scroll.contentSize = CGSizeMake(size.width * kCount, 0); // 内容尺寸
    scroll.pagingEnabled = YES; // 分页模式
    scroll.delegate = self;
    [self.view addSubview:scroll];
    _scroll = scroll;
}

#pragma mark 添加滚动显示的图片
- (void)addScrollImages
{
    CGSize size = _scroll.frame.size;
    
    for (int i = 0; i<kCount; i++) {
        // 1.显示图片
        NSString *name = [NSString stringWithFormat:@"new_feature_%d.png", i + 1];
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:name];
        // 2.设置frame
        imageView.frame = CGRectMake(i * size.width, 0, size.width, size.height);
        [_scroll addSubview:imageView];
    }
}
#pragma mark 添加分页指示器
- (void)addPageControl
{
    CGSize size = self.view.frame.size;
    UIPageControl *page = [[UIPageControl alloc] init];
    page.center = CGPointMake(size.width * 0.5, size.height * 0.95);
    page.numberOfPages = kCount;
    page.currentPageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"new_feature_pagecontrol_checked_point.png"]];
    page.pageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"new_feature_pagecontrol_point.png"]];
    page.bounds = CGRectMake(0, 0, 150, 0); [self.view addSubview:page]; _page = page;
}
#pragma mark - 滚动代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    _page.currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;
}</span>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值