iOS实践03
主要目标:版本新特性界面,新浪授权界面(登录界面)的处理
任务基本完成了,基本的框架也就到这了,接下来的应该是首页获取微博了。
1.版本新特性,可以单独作为一个model,写完之加入到项目中。我们新建一个mvc方式的分组Newpart,主要应用的就是那个scrollview,有点类似于广告轮播,这个换成手动的切换图片。
2.在appdelegate中将window的根控制器换成newpartController,完成效果后在处理他们之间的逻辑。
3.添加UIScrollView来实现滚动,添加图片,设置scroll的滚动属性(代码:009)
// 009
// 新特性控制器的scroll设置
- (void)viewDidLoad
{
[super viewDidLoad]; // 初始化scroll
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
// 设置scroll的代理
scroll.delegate = self;
// 添加到view上
[self.view addSubview:scroll]; // 添加图片
CGFloat imageW = self.view.frame.size.width;
CGFloat imageH = self.view.frame.size.height;
for (int index = ; index < SVNewPAartImageCount; index++) {
UIImageView *imageView = [[UIImageView alloc] init]; NSString *imageName = [NSString stringWithFormat:@"new_feature_%d-568h@2x", index+];
imageView.image = [UIImage imageNamed:imageName]; CGFloat imageX = index * imageW;
imageView.frame = CGRectMake(imageX, , imageW, imageH); [scroll addSubview:imageView]; } // 设置滚动的尺寸
scroll.contentSize = CGSizeMake(imageW * SVNewPAartImageCount, );
scroll.showsHorizontalScrollIndicator = NO; // 滚动条
scroll.pagingEnabled = YES; // 分页
scroll.bounces = NO;
}
4.添加pagecontrol(代码:010),使用scroll的代理完成pagecotrol的变换(代码:011)
// 010
// 添加pagecontrol
- (void)addPagecontrol
{
// 初始化page
UIPageControl *pageControl = [[UIPageControl alloc] init];
// 设置属性
pageControl.numberOfPages = SVNewPAartImageCount;
CGFloat centerX = self.view.frame.size.width * 0.5;
CGFloat centerY = self.view.frame.size.height * 0.95;
pageControl.center = CGPointMake(centerX, centerY);
pageControl.bounds = CGRectMake(, , , );
pageControl.userInteractionEnabled = NO;
// 添加page
[self.view addSubview:pageControl];
self.pageControl = pageControl; // 更改圆点的颜色
pageControl.currentPageIndicatorTintColor = SLColor(, , );
pageControl.pageIndicatorTintColor = SLColor(, , );
}
// 011
// 实现page的变换
#pragma mark UIScrollView的代理方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// 取出水平方向滚动的距离
CGFloat offsetX = scrollView.contentOffset.x;
// 计算页码
double pageDouble = offsetX / scrollView.frame.size.width;
int pageInt = (int)(pageDouble + 0.5);
self.pageControl.currentPage = pageInt;
}
5.为最后一张图片添加分享复选框和开始微博按钮(代码:012),实现从新特性跳转到首页(代码:013)
//
- (void)setupLastImageView:(UIImageView *)imageView
{
// 让imageview可以和用户进行交互
imageView.userInteractionEnabled = YES;
// 添加开始微博按钮
UIButton *startBtn = [[UIButton alloc] init];
[startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
[startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
// 设置frame
CGFloat centerX = imageView.frame.size.width * 0.5;
CGFloat centerY = imageView.frame.size.height * 0.6;
startBtn.center = CGPointMake(centerX, centerY);
startBtn.bounds = (CGRect){CGPointZero, startBtn.currentBackgroundImage.size};
// 设置文字
[startBtn setTitle:@"开始微博" forState:UIControlStateNormal];
[startBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// 绑定事件
[startBtn addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:startBtn]; // 添加选择框
UIButton *checkBox = [[UIButton alloc] init];
checkBox.selected = YES;
[checkBox setTitle:@"分享给大家" forState:UIControlStateNormal];
[checkBox setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
[checkBox setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
checkBox.bounds = CGRectMake(, , , );
CGFloat checkboxcenterX = centerX;
CGFloat checkboxcenterY = imageView.frame.size.height * 0.5;
checkBox.center = CGPointMake(checkboxcenterX, checkboxcenterY);
[checkBox setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
checkBox.titleLabel.font = [UIFont systemFontOfSize:];
[checkBox addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
// checkbox.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
checkBox.imageEdgeInsets = UIEdgeInsetsMake(, , , );
// checkbox.contentEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
[imageView addSubview:checkBox];
}
//
- (void)start
{
// 显示状态栏
[UIApplication sharedApplication].statusBarHidden = NO;
// 切换窗口的根控制器
self.view.window.rootViewController = [[SVTabbarController alloc] init];
}
- (void)checkboxClick:(UIButton *)checkbox
{
checkbox.selected = !checkbox.isSelected;
}
6.存储版本信息,当不是第一次安装本软件的时候不显示新特性界面,在appdelegate中完成存储和判断,(代码:014)
//
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. // 设置窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; // 版本信息的键值
NSString *key = @"CFBundleVersion";
// 取出沙盒中是上次存储的软件版本信息
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *lastVersion = [defaults stringForKey:key];
// 获得但前版本
NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key]; if ([currentVersion isEqualToString:lastVersion]) {
// 显示状态栏
[UIApplication sharedApplication].statusBarHidden = NO;
self.window.rootViewController = [[SVTabbarController alloc] init];
} else { // 新版本
self.window.rootViewController = [[SVNewpartController alloc] init];
// 存储新版本
[defaults setObject:currentVersion forKey:key];
[defaults synchronize];
}
// 显示窗口
[self.window makeKeyAndVisible]; return YES;
}
7.微博的Author授权,首先要成为新浪的开发者,这个很好申请的,我这个上次就已经弄好了,这次就直接用了。
8.这个授权也可以作为一个模块但度拿出来。想以后要是使用微博分享自己应用的一些动态就可以把这儿授权模块直接该一下就好,我们新建一个mvc组Author。
9.新浪的授权也是一个网页的形式,所以要用到webview,加载页面的时候iOS9也许会报错,是因为iOS要求使用更安全的https,需要在info.plist中加入一句话,(代码:特殊0)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</plist>
10.登陆后,通过webView的代理截取返回的code,并通过code换取accesstoken,在换取accesToken的方法中使用AFN发送请求
11.为了实现模型编程,新建一个用户账号模型SVAccount,为了优化账号的存取,添加一个AccountTool类,用来将用户归档保存。为后面的用户是否已经登录判断做基础
12.软件启动顺序:(图004),添加工具类weiboTool选择app的进入界面,在appdelegate中的判断就少了很多(代码015)
//
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 设置窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
// 显示窗口
[self.window makeKeyAndVisible]; // 先判断有无存储账号信息
SVAccount *account = [SVAccountTool account];
if (account) { // 之前登录成功
[SLWeiboTool chooseRootController];
} else { // 之前没有登录成功
self.window.rootViewController = [[SVAuthorController alloc] init];
}
return YES;
}
iOS实践03的更多相关文章
- 使用Bootstrap 3开发响应式网站实践03,轮播下方的内容排版
通常把一些重要信息.需要重点标注的信息放在轮播的下方显示,这部分区域用到了大字体的标题.副标题以及段落文字等. <div class="row" id="bigCa ...
- MatrixOne从入门到实践03——部署MatrixOne
MatrixOne从入门到实践--部署MatrixOne 前两章节我们简单介绍了MatrixOne和源码编译了MatrixOne.本章节将使用不同的部署方式,来部署MatrixOne的服务. 注意:不 ...
- 系统设计实践(03)- Instagram社交服务
前言 系统设计实践篇的文章将会根据<系统设计面试的万金油>为前置模板,讲解数十个常见系统的设计思路. 前置阅读: <系统设计面试的万金油> 系统设计实践(01) - 短链服务 ...
- iOS实践01
去年放假之前大概完成了新浪微博项目,到现在也忘得差不多了,打算在重新写一遍.之前的一些笔记在新浪的博客SleenXiu,在这主要是把新浪微博以随笔的形式写在这,方便以后的复习. 先看看之前主要完成的几 ...
- iOS实践04
第四天 微博数据展示:获取服务器数据,json数据的解析,MVC的使用,自定义cell高度的计算,一些分类的设计.已经是第四天了,虽然每天都有课程,但这个东西也基本完成了一大半吧,一些忘掉的知识也捡起 ...
- iOS实践02
第二天了,上了一天课,软件测试.数据挖掘.概率论,晚上了才有时间捣鼓捣鼓程序. 今天只是简单的做了一点.觉得自己思考的写不出来,只能简单的写一个过程,不像第一次写这个,少了很多思考的. 1.完善tab ...
- swift 实践- 03 -- UILabel
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // 标签 let ...
- 使用Axure RP原型设计实践03,制作一个登录界面的原型
本篇体验做一个登录界面的原型. 登录页 首先在Page Style里为页面设置背景色. 如果想在页面中加图片,就把Image部件拖入页面,并设置x和y轴.双击页面中的Image部件可以导入图片.在Im ...
- 在ASP.NET MVC中使用Knockout实践03,巧用data参数
使用Knockout,当通过构造函数创建View Model的时候,构造函数的参数个数很可能是不确定的,于是就有了这样的一个解决方案:向构造函数传递一个object类型的参数data. <inp ...
随机推荐
- Delphi下TLabel鼠标MouseEnter、MouseLeave更改颜色失灵
在Delphi 7下,如果想在鼠标MouseEnter.MouseLeave的时候改变TLabel自身的颜色,很多人可能会采用 Label.Color := clRed;这样的方式来实现,我当初也是一 ...
- Microsoft Azure 在北美 TechEd 大会上发布令人振奋的更新,帮助客户开始使用云服务
云计算因其速度.规模和成本节省等优势而备受众多企业青睐.但企业需帮助,才能以安全可靠的方式使用云,同时还要利用企业的现有投资, 才能实现这些优势.因此,在TechEd 大会上,我们推出了一些新的服务, ...
- Windows Azure Marketplace 为新增的 50 个国家/地区提供,并推出了令人振奋的新增内容,包括我们自己的 Bing 光学字符识别服务
尊敬的 Windows Azure Marketplace 用户: 我们有一些让人激动的新闻与您分享:我们现在为新增的 50 个国家/地区提供 Marketplace.自此,我们提供支持的国家/地区总 ...
- poj2608---几个字母映射到同一个数字
#include <stdio.h> #include <stdlib.h> #include<string.h> ]={,,,,,,,,,,,,,,,,,,,,, ...
- 通过iframe在其父窗口中打开隐藏元素
先上代码 $(".login-box,#dl,.top_01 a:eq(1)").click(function(){ if(self!=top){ parent.$("# ...
- Mac 上开启一个简单的服务器
终端输入命令: python -m SimpleHTTPServer 会开启一个端口为8000的本地服务器.
- DataTable 修改列名 删除列 调整列顺序
DataTable myDt =dt;//删除列myDt.Columns.Remove("minArea");myDt.Columns.Remove("maxArea&q ...
- English - even though和even if用法解析
even though和even if的用法区别两者均可用于引导让步状语从句,其细微区别是: 1. even if 引导的从句是往往是假设性的,相当于汉语的“即使”“纵然”“就算”“哪怕”. 如:Th ...
- SQL XML process
declare @data xml set @data=' <bookstore> <book category="COOKING"> <title ...
- SSIS: Lookup组件高级用法,生成推断成员(inferred member)
将数据导入事实表如果无法匹配维度表的记录一般有两种处理方式. 一是将不匹配记录输出到一个表中待后续处理,然后重新导入.二是先生成维度Key,后续再完善维度key,本文指导各位使用第二种方式. 背景 比 ...