iOS开发项目篇—08新版本特性·SrollView

iOS开发项目篇—08新版本特性

一、简单说明

展示新版本的特性:第一次使用一些应用软件时,展示这个版本的软件的新特性,一般在第一次启动程序的时候显示。

1.什么情况下显示版本新特性:

(1)第一次使用某个软件时(X)

(2)第一次使用某个版本时,显示版本新特性(V)

2.怎么知道这个软件的版本呢?

在plist文件里,bundle version中显示版本号。

3.如何显示版本新特性?

应该在YYAppDelegate.m中进行判断;

如果是第一次使用这个版本,那么就显示版本新特性(设置为window的根控制器),如果不是的话,那么就显示“首页”的控制器。

新建一个控制器,使用UIScore来显示新特性。

4.如何知道是第一次使用这个版本呢?

比较上次的使用情况。把每次使用的软件的版本号存储到沙盒中,当下一次打开软件时,取出上一次保存的版本号,进行比较。

5.代码示例:

YYAppDelegate.m文件中的处理代码:

 1 //
 2 //  YYAppDelegate.m
 3 //
 4
 5 #import "YYAppDelegate.h"
 6 #import "YYTabBarViewController.h"
 7 #import "YYNewfeatureViewController.h"
 8
 9 @implementation YYAppDelegate
10
11 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
12 {
13
14    //1.创建窗口
15     self.window=[[UIWindow alloc]init];
16     self.window.frame=[UIScreen mainScreen].bounds;
17
18     //2.设置窗口的根控制器
19     //如何知道是否是第一次使用这个版本?可以通过比较上次使用的版本进行判断
20     NSString *versionKey=@"CFBundleVersion";
21     versionKey=(__bridge NSString *)kCFBundleVersionKey;
22
23     //从沙盒中取出上次存储的软件版本号(取出用户上次的使用记录)
24     NSUserDefaults *defaults=[[NSUserDefaults alloc]init];
25     NSString *lastVersion=[defaults objectForKey:versionKey];
26
27     //获得当前打开软件的版本号
28     NSString *currentVersion=[NSBundle mainBundle].infoDictionary[versionKey];
29     if ([currentVersion isEqualToString:lastVersion]) {//当前版本号==上次使用的版本号
30            self.window.rootViewController=[[YYTabBarViewController alloc]init];
31 //         self.window.rootViewController=[[YYNewfeatureViewController alloc]init];
32     }else{//当前版本号!=上次使用的版本号:显示新版本的特性
33            self.window.rootViewController=[[YYNewfeatureViewController alloc]init];
34         //存储这个使用的软件版本
35         [defaults setObject:currentVersion forKey:versionKey];
36         //立刻写入
37         [defaults synchronize];
38     }
39
40     //3.显示窗口(主窗口)
41     [self.window makeKeyAndVisible];
42     return YES;
43 }

代码说明:

(1)比较大小,不能转浮点数,其实只要比较字符串不一样就是新的了。

(2)bundle version在Xcode中的真实类型为CFbundeVersion。

(3)Foundation和core foundation的数据类型是可以相互转换的,在两个框架之间比较安全的转换是桥接转换。

1 NSString *text = @"啊哈哈哈哈";
2
3 CFStringRef str = (__bridge CFStringRef)text;
4
5 NSString\NSArray\NSDictionary : Foundaiton
6
7 CFStringRef\CFArrayRef\CFDictionaryRef :  Core Foundation
8
9 // Foundation和Core Foundation的数据类型是可以相互转换的,必须用__bridge关键字进行桥接转换

二、新建一个展示新版本特性的控制器

1.导入图片素材

2.新建一个控制器类

3.实现代码

YYNewfeatureViewController.m文件

  1 //
  2 //  YYNewfeatureViewController.m
  3 //
  4
  5 #import "YYNewfeatureViewController.h"
  6 #define YYNewfeatureImageCount    4
  7 @interface YYNewfeatureViewController ()<UIScrollViewDelegate>
  8 @property(nonatomic,strong)UIPageControl *pageControl;
  9
 10 @end
 11
 12 @implementation YYNewfeatureViewController
 13
 14
 15 - (void)viewDidLoad
 16 {
 17     [super viewDidLoad];
 18     //1.添加UIScrollView
 19     [self setupScrollView];
 20     //2.添加pageControl
 21     [self setupPageControl];
 22 }
 23 /**
 24  *添加UIScrollVie
 25  */
 26 -(void)setupScrollView
 27 {
 28     //1.添加UIScrollVie
 29     //创建
 30     UIScrollView *scrollView=[[UIScrollView alloc]init];
 31     //设置frame
 32     scrollView.frame=self.view.bounds;
 33     //设置代理
 34     scrollView.delegate=self;
 35     //添加到view
 36     [self.view addSubview:scrollView];
 37
 38     //2.添加图片
 39     //设置每张图片的宽高和scrollView的一致
 40     CGFloat imageW=scrollView.width;
 41     CGFloat imageH=scrollView.height;
 42     //添加四张图片
 43     for (int i=0; i<YYNewfeatureImageCount; i++) {
 44         //创建ImageView
 45         UIImageView *imageView=[[UIImageView alloc]init];
 46         NSString *name=[NSString stringWithFormat:@"new_feature_%d",i+1];
 47 //        if ([UIScreen mainScreen].bounds.size.height==568.0) {
 48 //            name=[name stringByAppendingString:@"-568h"];
 49 //        }
 50         if (FourInch) {//需要手动去加载4英寸对应的[email protected]图片
 51             name=[name stringByAppendingString:@"-568h"];
 52         }
 53         imageView.image=[UIImage imageWithName:name];
 54
 55         //把ImageView添加到scrollView上
 56         [scrollView addSubview:imageView];
 57
 58         //设置imageView的frame
 59         imageView.y=0;
 60         imageView.width=imageW;
 61         imageView.height=imageH;
 62         imageView.x=i*imageW;
 63     }
 64     //设置其他的属性
 65     //设置活动范围
 66     scrollView.contentSize=CGSizeMake(YYNewfeatureImageCount*imageW, 0);
 67     //设置背景颜色
 68     scrollView.backgroundColor=YYColor(246, 246, 246);
 69     //隐藏水平滚动条
 70     scrollView.showsHorizontalScrollIndicator=NO;
 71 //    scrollView.pagingEnabled=YES;
 72     //去除弹簧效果
 73     scrollView.bounces=NO;
 74 }
 75
 76 /**
 77  *2.添加pageControl
 78  */
 79 -(void)setupPageControl
 80 {
 81     UIPageControl *pageControl=[[UIPageControl alloc]init];
 82     //设置一共有几页
 83     pageControl.numberOfPages=YYNewfeatureImageCount;
 84     //设置显示的位置
 85     pageControl.centerX=self.view.width*0.5;
 86     pageControl.centerY=self.view.height-30;
 87     //把pageControl添加到view上
 88     [self.view addSubview:pageControl];
 89
 90     //设置圆点的颜色
 91     //当前页的圆点的颜色
 92     pageControl.currentPageIndicatorTintColor=YYColor(253, 98, 42);
 93     //其它叶的圆点的颜色
 94     pageControl.pageIndicatorTintColor=YYColor(189, 189, 189);
 95     self.pageControl=pageControl;
 96
 97 }
 98 #pragma mark-UIScrollViewDelegate
 99 -(void)scrollViewDidScroll:(UIScrollView *)scrollView
100 {
101 //    YYLog(@"scrollViewDidScroll----%f",scrollView.contentOffset.x);
102     //拿到浮点数进行四舍五入
103     double doublePage=scrollView.contentOffset.x/scrollView.width;
104     int intPage=(int)(doublePage + 0.5);
105     //设置当前页码
106     self.pageControl.currentPage=intPage;
107
108 }
109 #pragma mark-隐藏状态栏
110 -(BOOL)prefersStatusBarHidden
111 {
112     return YES;
113 }
114 @end

4.实现细节

(1)设置活动范围 scrollView.contentSize=CGSizeMake(YYNewfeatureImageCount*imageW, 0);

(2)设置背景颜色 scrollView.backgroundColor=YYColor(246, 246, 246);

(3)隐藏水平滚动条 scrollView.showsHorizontalScrollIndicator=NO;

(4)去除弹簧效果scrollView.bounces=NO;

(5)补充:在pch文件中得宏定义

 1 //
 2 //  Prefix header
 3 //
 4 //  The contents of this file are implicitly included at the beginning of every source file.
 5 //
 6
 7 #import <Availability.h>
 8
 9 #ifndef __IPHONE_5_0
10 #warning "This project uses features only available in iOS SDK 5.0 and later."
11 #endif
12
13 #ifdef __OBJC__
14     #import <UIKit/UIKit.h>
15     #import <Foundation/Foundation.h>
16     #import "UIImage+Extension.h"
17     #import "UIBarButtonItem+Extension.h"
18     #import "UIView+Extension.h"
19
20 #ifdef DEBUG // 调试状态, 打开LOG功能
21 #define YYLog(...) NSLog(__VA_ARGS__)
22 #else // 发布状态, 关闭LOG功能
23 #define YYLog(...)
24 #endif
25
26 // 颜色
27 #define YYColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
28
29 // 随机色
30 #define YYRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
31
32 // 是否为iOS7
33 #define iOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0)
34
35 //是否为4英寸
36 #define FourInch ([UIScreen mainScreen].bounds.size.height==568.0)
37 #endif

5.实现效果

程序启动后的引导(新特性界面)

(1)关于加载图片的说明

当手机屏幕是3.5的时候,自动加载@2x的图片

当手机屏幕是4.0的时候,自动加载[email protected]的图片

拖入图片素材后,显示如下:

但是如果把模拟器调整为4.0英寸时,在程序运行中并没有自动加载[email protected]的图片。通过下面的图片(home键变成了椭圆)可以看出来。

说明:只有是启动图片的时候才会自动去加载[email protected]的图片,所以这里需要我们手动去加载。

判断:如果是4英寸的屏幕,那么就加载[email protected]的图片。

if ([UIScreen mainScreen].bounds.size.height==568.0) {

    name=[name stringByAppendingString:@"-568h"];

}

在项目中把是否为4英寸的判断定义为一个宏

#define FourInch ([UIScreen mainScreen].bounds.size.height==568.0)

注意:如果一张图片,它下面的标示为Unassigned,说明Xcode5不知道将来这张图片会用在什么地方,不会打包到mainbundle中去,即相当于图片不存在。

告诉Xcode图片是有用的,解决方法:

iOS开发项目篇—08新版本特性·SrollView,布布扣,bubuko.com

时间: 2024-08-25 18:52:17

iOS开发项目篇—08新版本特性·SrollView的相关文章

iOS开发项目篇—09新版本特性&#183;分享

iOS开发项目篇—09新版本特性·分享和开始 一.ios开发中图片的加载 图片的加载: [UIImage imageNamed:@"home"];  加载png图片 (一)非retina屏幕 (1)3.5 inch(320 x 480) * home.png (二)retina屏幕 (1)3.5 inch(640 x 960) * [email protected] (2)4.0 inch(640 x 1136) * [email protected](如果home是程序的启动图片,才

iOS开发项目篇—20存储账号信息

iOS开发项目篇—20存储账号信息 一.简单说明 1.不论请求是否成功,都在发送Post请求后,隐藏遮罩. 2.在授权成功后,切换根控制器. (1)说明 切换到控制器有几种情况,要么是切换到新特性,要么是切换到“首页”. 没有必要每次进入程序都需要登录,且每次返回的数据都是一样的,所以只需要把拿到的信息保存到沙盒里就可以了. 判断上次有没有登录成功(把拿到的access_token保存到沙盒中,如果沙盒中有access_token,说明上次登录成功),如果上次登陆成功,那么就判断是否要进入新特性

iOS开发项目篇—21抽取工具类

iOS开发项目篇—21抽取工具类 一.抽取宏 把和应用相关的信息抽取出来 App Key:1972915028 App Secret:b255603c4dfd82b4785bf9a808ce2662 回调地址:http://www.cnblogs.com/wendingding/ (1)appkey和回调页面在很多地方都要用到 (2)如果是不同应用的话,只需要把这几个参数换掉就可以了.把它们抽取成一个宏,写到pch文件中. 项目的PCH文件 1 #import <Availability.h>

iOS开发项目篇-01环境搭建

iOS开发项目篇-01环境搭建 一.基本过程 1.新建一个项目 (1)删除storyboard (2)在配置界面中,把main  删除,手动设置 2.准备素材 图片素材如下: 这个项目是模仿新浪,实现一个山寨的新浪微博系统,新版本的系统中已经放弃了非视网膜屏幕. 说白了,这种情况下,如果手机是3.5英寸的ios7系统,则看不到该启动动画. 设置方法,右键单击show in finder,修改json文件. Contents.json,对文件进行修改,让系统启动画面对3.5英寸的ios7系统提供支

iOS开发项目篇—16OAuth授权简介

iOS开发项目篇—16OAuth授权简介 一.资源的授权 在互联网行业,公司要能长期存活下来,用户量很重要,比如腾讯.新浪,它们的用户量是非常巨大的 要想长期留住用户,用户资源(数据)的管理也很重要,如果你经常在不经过用户同意的情况下,把用户的一些资源共享出去,那肯定是留不住用户的,甚至会遭到法律的制裁 但是,有时候确实要把某些用户资源共享出去,比如第三方想访问用户的QQ数据.第三方想访问用户的新浪微博数据 要想把用户资源共享出去,就必须取得用户的同意,那么这里就有个资源授权的问题 资源授权的方

学习IOS开发项目篇--如何让程序在后台保持挂起状态

程序的状态分为:前台运行,后台挂起,后台休眠,为了让项目的网络请求保持活跃状态,需要对程序进行设置. 在applicationDidEnterBackground方法中调用下面的方法,可以让程序进入挂起状态,但在未知时间内,可能会被系统设置为休眠,如果在将程序设置为播放器,并且循环播放一个MP3文件,可以保持永久挂起状态. UIBackgroundTaskIdentifier task =[application beginBackgroundTaskWithExpirationHandler:

iOS开发项目篇—28自定义UITextView

iOS开发项目篇—28自定义UITextView 一.简单说明 1.要实现的效果 2.分析 (1)UITextField 1.最多只能输入一行文字 2.能设置提醒文字(placehoder) 3.不具备滚动功能 (2)UITextView 1.能输入N行文字(N>0) 2.不能设置提醒文字(没有placehoder属性) 3.具备滚动功能 需求:技能输入多行文字,又具备文字提醒功能. 这里选择自定义一个类,让其继承自UITextView类,为其添加一个设置文字提醒的功能. 二.实现 自定义UI控

iOS开发项目篇—54&quot;设置&quot;界面的搭建

iOS开发项目篇—54"设置"界面的搭建 一.实现 新建一个设置控制器,当点击“我”控制器导航栏“设置”按钮时,即跳转到该界面 1.在“我”控制器中对导航栏“设置按钮”的处理 1 // 2 // YYProfileViewController.m 3 // 4 5 #import "YYProfileViewController.h" 6 #import "YYCommonGroup.h" 7 #import "YYCommonItem

iOS开发项目篇—36封装微博业务

iOS开发项目篇—36封装微博业务 一.简单说明 1.请求参数面向模型 2.请求结果面向模型 3.对控制器来说应该屏蔽业务细节.不让控制器关心(知道)业务细节,它只需要知道自己在做某个业务 @通过一个专门的业务处理类:处理微博业务细节 说明: 业务:加载新的微博首页数据 实现:给新浪服务器发送一个GET请求 业务:加载更多的首页微博数据 实现1:给新浪服务器发送一个GET请求 实现2:去沙盒中加载以前离线缓存的微博数据  二.实现 1.新建一个微博业务处理类,继承自NSObject 微博业务处理