IOS开发中新特性的实现
来源:互联网 发布:程序员的思维锻炼 编辑:程序博客网 时间:2024/05/17 05:11
一、首先判断版本号高低,在info.plist中,有几个版本号,
要想判断版本号的高低,需要做三件事,
一 拿到以前的版本号
NSString *key = @"CFBoundleVersion";
//上一次的使用版本(存储在沙盒中的版本号)
NSString *lastVersion = [[NSUserDefaultsstandardUserDefaults]objectForKey:key];
二 拿到当前的版本号
NSString *currentVersion = [NSBundlemainBundle].infoDictionary[key];
三 比较俩个版本号
if([currentVersionisEqualToString:lastVersion]){//版本号相同:这次打开和上次打开的是同一个版本
self.window.rootViewController = [[ViewControlleralloc]init];
}else{//这次打开的版本和上一次不一样,显示新特性
self.window.rootViewController = [[YYNewViewControlleralloc]init];
// 如当前版本号大于以前的的版本号,将当前的版本号存进沙盒
[[NSUserDefaultsstandardUserDefaults]setObject:currentVersionforKey:key];
[[NSUserDefaultsstandardUserDefaults]synchronize];
}
#define YYNewfeatureCount 4
// RGB颜色
#define YYColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
- (void)viewDidLoad{
[superviewDidLoad];
// 1.创建一个scrollView:显示所有的新特性图片
UIScrollView *scrollView = [[UIScrollViewalloc]init];
scrollView.frame = self.view.bounds;
[self.viewaddSubview:scrollView];
self.scrollView = scrollView;
// 2.添加图片到scrollView中
CGFloat scrollW = scrollView.width;
CGFloat scrollH = scrollView.height;
for (int i =0; i<YYNewfeatureCount; i++) {
UIImageView *imageView = [[UIImageViewalloc]init];
imageView.width = scrollW;
imageView.height = scrollH;
imageView.y = 0;
imageView.x = i * scrollW;
// 显示图片
NSString *name = [NSStringstringWithFormat:@"new_feature_%d", i +1];
imageView.image = [UIImageimageNamed:name];
[scrollView addSubview:imageView];
// 如果是最后一个imageView,就往里面添加其他内容
if (i == YYNewfeatureCount -1) {
[self setupLastImageView:imageView];
}
}
// 3.设置scrollView的其他属性
// 如果想要某个方向上不能滚动,那么这个方向对应的尺寸数值传0即可
scrollView.contentSize = CGSizeMake(YYNewfeatureCount * scrollW,0);
scrollView.bounces = NO; // 去除弹簧效果
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator =NO;
scrollView.delegate = self;
// 4.添加pageControl:分页,展示目前看的是第几页
UIPageControl *pageControl = [[UIPageControlalloc]init];
pageControl.numberOfPages = YYNewfeatureCount;
pageControl.backgroundColor = [UIColorredColor];
pageControl.currentPageIndicatorTintColor = YYColor(253,98,42);
pageControl.pageIndicatorTintColor = YYColor(189, 189, 189);
pageControl.centerX = scrollW * 0.5;
pageControl.centerY = scrollH - 50;
[self.viewaddSubview:pageControl];
self.pageControl = pageControl;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
double page = scrollView.contentOffset.x / scrollView.width;
// 四舍五入计算出页码
self.pageControl.currentPage = (int)(page +0.5);
}
//初始化最后一个imageView
- (void)setupLastImageView:(UIImageView *)imageView
{
// 开启交互功能
imageView.userInteractionEnabled =YES;
// 1.分享给大家(checkbox)
UIButton *shareBtn = [[UIButtonalloc]init];
[shareBtn setImage:[UIImageimageNamed:@"new_feature_share_false"]forState:UIControlStateNormal];
[shareBtn setImage:[UIImageimageNamed:@"new_feature_share_true"]forState:UIControlStateSelected];
[shareBtn setTitle:@"分享给大家"forState:UIControlStateNormal];
[shareBtn setTitleColor:[UIColorblackColor]forState:UIControlStateNormal];
shareBtn.titleLabel.font = [UIFontsystemFontOfSize:15];
shareBtn.width = 200;
shareBtn.height = 30;
shareBtn.centerX = imageView.width *0.5;
shareBtn.centerY = imageView.height *0.65;
[shareBtn addTarget:selfaction:@selector(shareClick:)forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:shareBtn];
shareBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
// 2.开始首页
UIButton *startBtn = [[UIButtonalloc]init];
[startBtn setBackgroundImage:[UIImageimageNamed:@"new_feature_finish_button"]forState:UIControlStateNormal];
[startBtn setBackgroundImage:[UIImageimageNamed:@"new_feature_finish_button_highlighted"]forState:UIControlStateHighlighted];
startBtn.size = startBtn.currentBackgroundImage.size;
startBtn.centerX = shareBtn.centerX;
startBtn.centerY = imageView.height *0.75;
[startBtn setTitle:@"开始首页"forState:UIControlStateNormal];
[startBtn addTarget:selfaction:@selector(startClick)forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:startBtn];
}
- (void)shareClick:(UIButton *)shareBtn
{
// 状态取反
shareBtn.selected = !shareBtn.isSelected;
}
- (void)startClick
{
// 切换到主界面
UIWindow *window = [UIApplicationsharedApplication].keyWindow;
window.rootViewController = [[YYTabBarViewControlleralloc]init];
}
- IOS开发中新特性的实现
- iOS新特性实现3DTouch开发
- iOS开发学习之UIScrollerView实现新特性
- iOS开发 Swift3新特性
- ios开发-------- Xcode9新特性
- ios开发之iOS 11 SDK 的新特性
- 玩转iOS开发:iOS 11 新特性《Layout的新特性》
- 玩转iOS开发:iOS 11 新特性《UIKit新特性的基本认识》
- iOS 8 中新特性 - Swift 编程语言,一种接近自然语言的开发语言
- iOS学习笔记43-iOS9新特性和开发中常见的问题大总结
- ios开发xcode4.4(ios6)的一些新特性
- (0058)iOS开发之iOS8新特性IBDesignable的使用
- iOS程序实现程序的版本新特性显示功能
- iOS程序更新后新特性介绍界面的实现
- iOS 9 的新特性
- 【iOS开发系列】版本新特性界面
- iOS开发~Objective-C新特性
- 【IOS开发新技术】swift4.0 新特性
- android的sql表单新增字段- alter table
- [pat]1105. Spiral Matrix (25)
- iOS之旅--用CollectionView实现轮播图效果+封装方法
- php mysql大数据处理
- HDU 1002 A + B Problem II (JAVA大数)
- IOS开发中新特性的实现
- K--近邻算法示例
- Codeforces Round #277 (Div. 2)(A)模拟,打表
- 贝塞尔曲线精讲
- C++第1次实验
- ora-01403:未找到任何数据
- Injection for Xcode 不用build 查看效果.类似于HTML 的F5
- Node.js最新技术栈之Promise篇
- VS2015 OPENGL配置(X86平台)