*********版本新特性

#import "HWNewfeatureViewController.h"
#import "HWTabBarViewController.h"
#define HWNewfeatureCount 4 @interface HWNewfeatureViewController () <UIScrollViewDelegate>
@property (nonatomic, weak) UIPageControl *pageControl; @property (nonatomic, weak) UIScrollView *scrollView;
@end @implementation HWNewfeatureViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 1.创建一个scrollView:显示所有的新特性图片
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.frame = self.view.bounds;
[self.view addSubview:scrollView];
self.scrollView = scrollView; // 2.添加图片到scrollView中
CGFloat scrollW = scrollView.width;
CGFloat scrollH = scrollView.height;
for (int i = ; i<HWNewfeatureCount; i++) {
UIImageView *imageView = [[UIImageView alloc] init];
imageView.width = scrollW;
imageView.height = scrollH;
imageView.y = ;
imageView.x = i * scrollW;
// 显示图片
NSString *name = [NSString stringWithFormat:@"new_feature_%d", i + ];
imageView.image = [UIImage imageNamed:name];
[scrollView addSubview:imageView]; // 如果是最后一个imageView,就往里面添加其他内容
if (i == HWNewfeatureCount - ) {
[self setupLastImageView:imageView];
}
} #warning 默认情况下,scrollView一创建出来,它里面可能就存在一些子控件了
#warning 就算不主动添加子控件到scrollView中,scrollView内部还是可能会有一些子控件 // 3.设置scrollView的其他属性
// 如果想要某个方向上不能滚动,那么这个方向对应的尺寸数值传0即可
scrollView.contentSize = CGSizeMake(HWNewfeatureCount * scrollW, );
scrollView.bounces = NO; // 去除弹簧效果
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.delegate = self; // 4.添加pageControl:分页,展示目前看的是第几页
UIPageControl *pageControl = [[UIPageControl alloc] init];
pageControl.numberOfPages = HWNewfeatureCount;
pageControl.backgroundColor = [UIColor redColor];
pageControl.currentPageIndicatorTintColor = HWColor(, , );
pageControl.pageIndicatorTintColor = HWColor(, , );
pageControl.centerX = scrollW * 0.5;
pageControl.centerY = scrollH - ;
[self.view addSubview:pageControl];
self.pageControl = pageControl; // UIPageControl就算没有设置尺寸,里面的内容还是照常显示的
// pageControl.width = 100;
// pageControl.height = 50;
// pageControl.userInteractionEnabled = NO; // UITextField *text = [[UITextField alloc] init];
// text.frame = CGRectMake(10, 20, 100, 50);
// text.borderStyle = UITextBorderStyleRoundedRect;
// [self.view addSubview:text];
} - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
double page = scrollView.contentOffset.x / scrollView.width;
// 四舍五入计算出页码
self.pageControl.currentPage = (int)(page + 0.5);
// 1.3四舍五入 1.3 + 0.5 = 1.8 强转为整数(int)1.8= 1
// 1.5四舍五入 1.5 + 0.5 = 2.0 强转为整数(int)2.0= 2
// 1.6四舍五入 1.6 + 0.5 = 2.1 强转为整数(int)2.1= 2
// 0.7四舍五入 0.7 + 0.5 = 1.2 强转为整数(int)1.2= 1
} /**
* 初始化最后一个imageView
*
* @param imageView 最后一个imageView
*/
- (void)setupLastImageView:(UIImageView *)imageView
{
// 开启交互功能
imageView.userInteractionEnabled = YES; // 1.分享给大家(checkbox)
UIButton *shareBtn = [[UIButton alloc] init];
[shareBtn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
[shareBtn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
[shareBtn setTitle:@"分享给大家" forState:UIControlStateNormal];
[shareBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
shareBtn.titleLabel.font = [UIFont systemFontOfSize:];
shareBtn.width = ;
shareBtn.height = ;
shareBtn.centerX = imageView.width * 0.5;
shareBtn.centerY = imageView.height * 0.65;
[shareBtn addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:shareBtn];
// shareBtn.backgroundColor = [UIColor redColor];
// shareBtn.imageView.backgroundColor = [UIColor blueColor];
// shareBtn.titleLabel.backgroundColor = [UIColor yellowColor]; // top left bottom right // EdgeInsets: 自切
// contentEdgeInsets:会影响按钮内部的所有内容(里面的imageView和titleLabel)
// shareBtn.contentEdgeInsets = UIEdgeInsetsMake(10, 100, 0, 0); // titleEdgeInsets:只影响按钮内部的titleLabel
shareBtn.titleEdgeInsets = UIEdgeInsetsMake(, , , ); // imageEdgeInsets:只影响按钮内部的imageView
// shareBtn.imageEdgeInsets = UIEdgeInsetsMake(20, 0, 0, 50); // shareBtn.titleEdgeInsets
// shareBtn.imageEdgeInsets
// shareBtn.contentEdgeInsets // 2.开始微博
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];
startBtn.size = startBtn.currentBackgroundImage.size;
startBtn.centerX = shareBtn.centerX;
startBtn.centerY = imageView.height * 0.75;
[startBtn setTitle:@"开始微博" forState:UIControlStateNormal];
[startBtn addTarget:self action:@selector(startClick) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:startBtn];
} - (void)shareClick:(UIButton *)shareBtn
{
// 状态取反
shareBtn.selected = !shareBtn.isSelected;
} - (void)startClick
{
// 切换到HWTabBarController
/*
切换控制器的手段
1.push:依赖于UINavigationController,控制器的切换是可逆的,比如A切换到B,B又可以回到A
2.modal:控制器的切换是可逆的,比如A切换到B,B又可以回到A
3.切换window的rootViewController
*/
UIWindow *window = [UIApplication sharedApplication].keyWindow;
window.rootViewController = [[HWTabBarViewController alloc] init]; // modal方式,不建议采取:新特性控制器不会销毁
// HWTabBarViewController *main = [[HWTabBarViewController alloc] init];
// [self presentViewController:main animated:YES completion:nil];
} - (void)dealloc
{
HWLog(@"HWNewfeatureViewController-dealloc");
} /*
1.程序启动会自动加载叫做Default的图片
1> 3.5inch 非retain屏幕:Default.png
2> 3.5inch retina屏幕:Default@2x.png
3> 4.0inch retain屏幕: Default-568h@2x.png 2.只有程序启动时自动去加载的图片, 才会自动在4inch retina时查找-568h@2x.png
*/ /*
一个控件用肉眼看不见,有哪些可能
1.根本没有创建实例化这个控件
2.没有设置尺寸
3.控件的颜色跟父控件的背景色一样(实际上已经显示了,只不过用肉眼看不见)
4.透明度alpha <= 0.01
5.hidden = YES
6.没有添加到父控件中
7.被其他控件挡住了
8.位置不对
9.父控件发生了以上情况
10.特殊情况
* UIImageView没有设置image属性,或者设置的图片名不对
* UILabel没有设置文字,或者文字颜色和跟父控件的背景色一样
* UITextField没有设置文字,或者没有设置边框样式borderStyle
* UIPageControl没有设置总页数,不会显示小圆点
* UIButton内部imageView和titleLabel的frame被篡改了,或者imageView和titleLabel没有内容
* ..... 添加一个控件的建议(调试技巧):
1.最好设置背景色和尺寸
2.控件的颜色尽量不要跟父控件的背景色一样
*/
@end

**********HWNewfeatureViewController .h

#import <UIKit/UIKit.h>

@interface HWNewfeatureViewController : UIViewController

@end

************OAuth授权认证

#import "HWOAuthViewController.h"
#import "AFNetworking.h" @interface HWOAuthViewController () <UIWebViewDelegate> @end @implementation HWOAuthViewController - (void)viewDidLoad
{
[super viewDidLoad]; // 1.创建一个webView
UIWebView *webView = [[UIWebView alloc] init];
webView.frame = self.view.bounds;
webView.delegate = self;
[self.view addSubview:webView]; // 2.用webView加载登录页面(新浪提供的)
// 请求地址:https://api.weibo.com/oauth2/authorize
/* 请求参数:
client_id true string 申请应用时分配的AppKey。
redirect_uri true string 授权回调地址,站外应用需与设置的回调地址一致,站内应用需填写canvas page的地址。
*/
NSURL *url = [NSURL URLWithString:@"https://api.weibo.com/oauth2/authorize?client_id=3235932662&redirect_uri=http://"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
} #pragma mark - webView代理方法
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// HWLog(@"----webViewDidFinishLoad");
} - (void)webViewDidStartLoad:(UIWebView *)webView
{
// HWLog(@"----webViewDidStartLoad");
} - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// 1.获得url
NSString *url = request.URL.absoluteString; // 2.判断是否为回调地址
NSRange range = [url rangeOfString:@"code="];
if (range.length != ) { // 是回调地址
// 截取code=后面的参数值
int fromIndex = range.location + range.length;
NSString *code = [url substringFromIndex:fromIndex]; // 利用code换取一个accessToken
[self accessTokenWithCode:code];
} return YES;
} /**
* 利用code(授权成功后的request token)换取一个accessToken
*
* @param code 授权成功后的request token
*/
- (void)accessTokenWithCode:(NSString *)code
{
/*
URL:https://api.weibo.com/oauth2/access_token 请求参数:
client_id:申请应用时分配的AppKey
client_secret:申请应用时分配的AppSecret
grant_type:使用authorization_code
redirect_uri:授权成功后的回调地址
code:授权成功后返回的code
*/
// 1.请求管理者
AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
// mgr.responseSerializer = [AFJSONResponseSerializer serializer]; // AFN的AFJSONResponseSerializer默认不接受text/plain这种类型 // 2.拼接请求参数
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"client_id"] = @"";
params[@"client_secret"] = @"227141af66d895d0dd8baca62f73b700";
params[@"grant_type"] = @"authorization_code";
params[@"redirect_uri"] = @"http://";
params[@"code"] = code; // 3.发送请求
[mgr POST:@"https://api.weibo.com/oauth2/access_token" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
HWLog(@"请求成功-%@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
HWLog(@"请求失败-%@", error);
}];
}
@end

***

#import <UIKit/UIKit.h>

@interface HWOAuthViewController : UIViewController

@end

IOS第三天-新浪微博 - 版本新特性,OAuth授权认证的更多相关文章

  1. [iOS微博项目 - 1.7] - 版本新特性

    A.版本新特性 1.需求 第一次使用新版本的时候,不直接进入app,而是展示新特性界面 github: https://github.com/hellovoidworld/HVWWeibo       ...

  2. IOS 制作版本新特性

    创建版本新特性 页面(存放图片) HMNewfeatureViewController.m #define HMNewfeatureImageCount 4 #import "HMNewfe ...

  3. Atitit mac os 版本 新特性 attilax大总结

    Atitit mac os 版本 新特性 attilax大总结 1. Macos概述1 2. 早期2 2.1. Macintosh OS (系统 1.0)  1984年2 2.2. Mac OS 7. ...

  4. 【开源】OSharp3.3框架解说系列:重新开源及3.3版本新特性

    OSharp是什么? OSharp是个快速开发框架,但不是一个大而全的包罗万象的框架,严格的说,OSharp中什么都没有实现.与其他大而全的框架最大的不同点,就是OSharp只做抽象封装,不做实现.依 ...

  5. 《转》MySQL 5.7版本新特性连载

    MySQL 5.7版本新特性连载(一) 本文将和大家一起分享下5.7的新特性,不过我们要先从即将被删除的特性以及建议不再使用的特性说起.根据这些情况,我们在新版本及以后的版本中,应该不再使用,避免未来 ...

  6. Atitit.c# .net 3.5 4.0 4.5 5.0 6.0各个版本新特性战略规划总结

    Atitit.c# .net 3.5 4.0 各个版本新特性战略规划总结 1. --------------.Net Framework版本同CLR版本的关系1 2. paip.----------- ...

  7. c# .net 3.5 4.0 4.5 5.0 6.0各个版本新特性战略规划总结【转载】

    引用:http://blog.csdn.net/attilax/article/details/42014327 c# .net 3.5 4.0 各个版本新特性战略规划总结 1. ---------- ...

  8. Atitit..jdk java 各版本新特性 1.0 1.1 1.2 1.3 1.4 1.5(5.0) 1.6(6.0) 7.0 8.0 9.0 attilax 大总结

    Atitit..jdk java 各版本新特性 1.0 1.1 1.2 1.3 1.4 1.5(5.0) 1.6(6.0) 7.0 8.0 9.0 attilax 大总结 1.1. Java的编年史2 ...

  9. C# 语言历史版本特性(C# 1.0到C# 7.1汇总更新) C#各版本新特性 C#版本和.NET版本以及VS版本的对应关系

    C# 语言历史版本特性(C# 1.0到C# 7.1汇总更新) 2017年08月06日 11:53:13 阅读数:6705 历史版本 C#作为微软2000年以后.NET平台开发的当家语言,发展至今具有1 ...

随机推荐

  1. Linux创建定时任务

    例如: 要求每天23:59分备份lampp日志: 备份的文件名以当时的时间命名 格式为:201612241852_acces.log 备份到:/tmp/logs/目录下 1.新建shell脚本:vim ...

  2. Swagger(webapi自动生成接口说明文档)

    1.引入Swagger.Net.UI和Swashbuckle包 2.卸载重复包Swagger.Net 3.多余的SwaggerUI文件夹 4.项目属性->勾选生成xml文档文件 5.添加类Swa ...

  3. Python-类的属性

    类的属性,可以称为成员变量 类的方法,可以称为成员函数   对象的创建 - 创建对象的过程称之为实例化:当一个对象被创建后,包含三个方面的特性:对象句柄.属性和方法. - 句柄用于区分不同的对象(实例 ...

  4. Unity引擎下最快的Xml读取器:UnityRapidXml

    近期发现无论是系统的System.Xml还是Mono.Xml,其实都有这样或者那样的问题,所以决定自己搞一个快一点的xml parse.以前在C++里用过rapidxml,这个确实是神一般的存在,速度 ...

  5. javaweb学习笔记之servlet01

    一.Servlet概述 A servlet is a small Java program that runs within a Web server. Servlets receive and re ...

  6. PDA无线数据采集器在仓库管理系统中的应用

    条码数据采集器在仓库管理系统中的应用,条码数据采集器,顾名思义就是通过扫描货物条码,对货物进行数量分类采集,方便仓库正规化管理.条码数据采集器是现代化条码仓库管理系统中不可缺少的一部分,能提升企业的整 ...

  7. orcal 操作

    清空表数据(不清除表结构): truncate table 表名

  8. Ice-E(Embedded Internet Communications Engine)移植到s3c2440A(arm9)linux(2.6.12)上的

    2009-03-26 18:31:31 原文链接 1.前言 ICE-E是ICE在嵌入式上运行的一个版本,与ICE比较如下: Category Ice 3.3.0 Ice-E 1.3.0 Thread ...

  9. Content Negotiation in ASP.NET Web API

    本文描述Web API实现内容协商(content negotiation). The HTTP specification (RFC 2616) defines content negotiatio ...

  10. java合并pdf

    一.开发准备 下载pdfbox-app-1.7.1.jar包;下载地址:http://download.csdn.net/detail/yanning1314/4852276 二.简单小例子 在开发中 ...