//

VTMagic的使用

//  CFOrderViewController.m

//  qifuyuniOS

////

/**

*  @author 李洪强, 16-08-30 10:08:50

*

*  原生开发

*/

#import "CFOrderViewController.h"

#import "ZZChatViewController.h"

#import "CFCommodityController.h"

#import "WXApi.h"

#import "AppDelegate.h"

#import "VTMagic.h"

//待支付

#import "CFtobePaidTableCtrl.h"

//代发货

#import "CFtoBeShippedTableCtrl.h"

//待收货

#import "CFreceiptOfGoodsTabelCtrl.h"

//我的订单

#import "CFmyOrderTabelCtrl.h"

//

@interface CFOrderViewController ()<UIAlertViewDelegate,UIScrollViewDelegate,VTMagicViewDataSource,VTMagicViewDelegate>

@property(nonatomic,retain) VTMagicController  *magicController;

//******************************************

/**

*  @author 李洪强, 16-08-30 10:08:50

*

*  原生开发

*/

/** 横线View1 */

@property (weak, nonatomic) IBOutlet UIView *orangeView1;

/** 横线View2 */

@property (weak, nonatomic) IBOutlet UIView *orangeView2;

/** 横线View3 */

@property (weak, nonatomic) IBOutlet UIView *orangeView3;

/** 横线View4 */

@property (weak, nonatomic) IBOutlet UIView *orangeView4;

/** 存放顶部所有标题的View */

//@property (weak, nonatomic) IBOutlet UIView *titlesView;

/** 存放所有内容的scrollView */

@property (weak, nonatomic) IBOutlet UIScrollView *contentsScrollView;

/** 待支付*/

//To be paid

@property (weak, nonatomic) IBOutlet UIButton *tobePaidBtn;

/** 待发货*/

//toBeShipped

@property (weak, nonatomic) IBOutlet UIButton *toBeShippedBtn;

/** 待收货*/

//receiptOfGoods

@property (weak, nonatomic) IBOutlet UIButton *receiptOfGoodsBtn;

/**我的订单*/

//myOrder

@property (weak, nonatomic) IBOutlet UIButton *myOrderBtn;

/** 标签栏底部的红色指示器 */

@property (nonatomic, weak) UIView *indicatorView;

/** 当前选中的按钮 */

@property (nonatomic, weak) UIButton *selectedButton;

/** 顶部的按钮 */

@property (nonatomic, weak) UIButton *Button1;

/** 顶部的所有标签 */

@property (nonatomic, weak) UIView *titlesView;

/** 底部的所有内容 */

@property (nonatomic, weak) UIScrollView *contentView;

//cookie

@property(nonatomic,strong)NSDictionary *userInfo;

@property(nonatomic,copy)NSString * phoneNo;

@end

@implementation CFOrderViewController

- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

}

-(void)viewDidAppear:(BOOL)animated

{

[super viewDidAppear:animated];

[_magicController.view setFrame:CGRectMake(0, 0, CFScreenW, self.view.height-50)];

}

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

self.navigationItem.title = @"我的订单";

// 设置导航栏

// [self setupNav];

//    // 01 - 初始化子控制器

//    [self setupChildVces];

//

//    // 02 - 设置顶部的标签栏

//    [self setupTitlesView];

//

//    // 03 - 底部的scrollView

//    [self setupContentView];

//

//    //设置控制器为UIScrollView的代理

//    self.contentView.delegate = self;

/*****fix****/

[self initView];

}

#pragma mark 初始化View

-(void)initView

{

[self addChildViewController:self.magicController];

[self.view addSubview:_magicController.view];

[_magicController.magicView reloadData];

}

- (NSArray<NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView {

return @[@"待支付",@"待发货",@"待收货",@"我的订单"];

}

- (UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex {

static NSString *itemIdentifier = @"itemIdentifier";

UIButton *menuItem = [magicView dequeueReusableItemWithIdentifier:itemIdentifier];

if (!menuItem) {

menuItem = [UIButton buttonWithType:UIButtonTypeCustom];

[menuItem setTitleColor:RGBCOLOR(0, 0, 0) forState:UIControlStateNormal];

[menuItem setTitleColor:[UIColor colorWithHex:@"FE6F07"] forState:UIControlStateSelected];

menuItem.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:16.f];

}

return menuItem;

}

- (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex {

switch (pageIndex) {

case 0:

{

static NSString *bookmarkId = @"CFtobePaidTableCtrl.identifier";

CFtobePaidTableCtrl *cr = [magicView dequeueReusablePageWithIdentifier:bookmarkId];

if (!cr)

cr = [CFtobePaidTableCtrl new];

return cr;

}

break;

case 1:

{

static NSString *bookmarkId = @"CFtoBeShippedTableCtrl.identifier";

CFtoBeShippedTableCtrl *cr = [magicView dequeueReusablePageWithIdentifier:bookmarkId];

if (!cr)

cr = [CFtoBeShippedTableCtrl new];

return cr;

}

break;

case 2:

{

static NSString *bookmarkId = @"CFreceiptOfGoodsTabelCtrl.identifier";

CFreceiptOfGoodsTabelCtrl *cr = [magicView dequeueReusablePageWithIdentifier:bookmarkId];

if (!cr)

cr = [CFreceiptOfGoodsTabelCtrl new];

return cr;

}

break;

case 3:

{

static NSString *bookmarkId = @"CFmyOrderTabelCtrl.identifier";

CFmyOrderTabelCtrl *cr = [magicView dequeueReusablePageWithIdentifier:bookmarkId];

if (!cr)

cr = [CFmyOrderTabelCtrl new];

return cr;

}

break;

default:

break;

}

return nil;

}

- (VTMagicController *)magicController {

if (!_magicController) {

_magicController = [[VTMagicController alloc] init];

_magicController.magicView.navigationColor = [UIColor whiteColor];

_magicController.magicView.sliderColor = [UIColor colorWithHex:@"FE6F07"];

_magicController.magicView.layoutStyle = VTLayoutStyleDivide;

_magicController.magicView.switchStyle = VTSwitchStyleDefault;

_magicController.magicView.navigationHeight = 40.f;

_magicController.magicView.dataSource = self;

_magicController.magicView.delegate = self;

}

return _magicController;

}

/**01 添加子控制器*/

- (void)setupChildVces{

//待支付

CFtobePaidTableCtrl *toBePaidCtrl = [[CFtobePaidTableCtrl alloc]initWithNibName:@"CFtobePaidTableCtrl" bundle:nil];

[toBePaidCtrl.view setFrame:CGRectMake(0, 0, CFScreenW, CFScreenH)];

//toBePaidCtrl.view.backgroundColor = [UIColor colorWithRed:0.300 green:0.198 blue:1.000 alpha:1.000];

toBePaidCtrl.title = @"待支付";

[self addChildViewController:toBePaidCtrl];

//代发货

//#import "CFtoBeShippedTableCtrl.h"

CFtoBeShippedTableCtrl *toBeShippedCtrl = [[CFtoBeShippedTableCtrl alloc]init];

// toBeShippedCtrl.view.backgroundColor = [UIColor colorWithRed:1.000 green:0.893 blue:0.387 alpha:1.000];

toBeShippedCtrl.title = @"待发货";

[self addChildViewController:toBeShippedCtrl];

//待收货

//#import "CFreceiptOfGoodsTabelCtrl.h"

CFreceiptOfGoodsTabelCtrl *receiptOfGoodsCtrl = [[CFreceiptOfGoodsTabelCtrl alloc]init];

// receiptOfGoodsCtrl.view.backgroundColor = [UIColor colorWithRed:1.000 green:0.118 blue:0.783 alpha:1.000];

receiptOfGoodsCtrl.title = @"待收货";

[self addChildViewController:receiptOfGoodsCtrl];

//我的订单

//#import "CFmyOrderTabelCtrl.h"

CFmyOrderTabelCtrl *myOrderCtrl = [[CFmyOrderTabelCtrl alloc]init];

//myOrderCtrl.view.backgroundColor = [UIColor colorWithRed:1.000 green:0.160 blue:0.108 alpha:1.000];

myOrderCtrl.title = @"我的订单";

[self addChildViewController:myOrderCtrl];

//   NSLog(@"子控制器有: %@",self.childViewControllers);

}

/**

*  @author 李洪强, 16-08-30 16:08:10

*

*   **02 - 设置顶部的标签栏*/

- (void)setupTitlesView{

// 标签栏整体

UIView *titlesView = [[UIView alloc] init];

titlesView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7];

titlesView.width = self.view.width;

titlesView.height = CFTitlesViewH;

titlesView.y = 0;

[self.view addSubview:titlesView];

self.titlesView = titlesView;

// 底部的橙色指示器

UIView *indicatorView = [[UIView alloc] init];

indicatorView.backgroundColor = [UIColor orangeColor];

indicatorView.height = 2;

indicatorView.tag = -1;

indicatorView.y = titlesView.height - indicatorView.height;

self.indicatorView = indicatorView;

// 内部的子标签

CGFloat width = titlesView.width / self.childViewControllers.count;

CGFloat height = titlesView.height;

for (NSInteger i = 0; i<self.childViewControllers.count; i++) {

UIButton *button = [[UIButton alloc] init];

button.tag = i;

button.height = height;

button.width = width;

button.x = i * width;

UIViewController * vc = self.childViewControllers[i];

[button setTitle:vc.title forState:UIControlStateNormal];

//        [button layoutIfNeeded]; // 强制布局(强制更新子控件的frame)

[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

[button setTitleColor:[UIColor orangeColor] forState:UIControlStateDisabled];

button.titleLabel.font = [UIFont systemFontOfSize:14];

[button addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];

[titlesView addSubview:button];

// 默认点击了第一个按钮

if (i == 0) {

button.enabled = NO;

self.selectedButton = button;

// 让按钮内部的label根据文字内容来计算尺寸

[button.titleLabel sizeToFit];

self.indicatorView.width = button.width;

self.indicatorView.centerX = button.centerX;

}

}

[titlesView addSubview:indicatorView];

/**

李洪强-2016-8-31

添加顶部标题栏的竖线*/

CGFloat lineW = 1;

CGFloat lineH = 20;

for(NSInteger i = 0; i < 3; i++){

UIView *lineView = [[UIView alloc]init];

lineView.backgroundColor = [UIColor colorWithWhite:0.845 alpha:1.000];

lineView.x = i*self.selectedButton.width + self.selectedButton.width;

lineView.y = 12;

lineView.frame = CGRectMake(lineView.x, lineView.y, lineW, lineH);

[self.titlesView addSubview:lineView];

}

}

- (void)titleClick:(UIButton *)button

{

// 修改按钮状态

self.selectedButton.enabled = YES;

button.enabled = NO;

self.selectedButton = button;

// 动画

[UIView animateWithDuration:0.25 animations:^{

self.indicatorView.width = button.width;

self.indicatorView.centerX = button.centerX;

}];

// 滚动

CGPoint offset = self.contentView.contentOffset;

offset.x = button.tag * self.contentView.width;

[self.contentView setContentOffset:offset animated:YES];

}

// 03 - 底部的scrollView

- (void)setupContentView{

// 不要自动调整inset

self.automaticallyAdjustsScrollViewInsets = NO;

UIScrollView *contentView = [[UIScrollView alloc] init];

// contentView.frame = self.view.bounds;

contentView.frame = CGRectMake(self.view.x, 40, CFScreenW, CFScreenH - 150);

contentView.delegate = self;

contentView.pagingEnabled = YES;

[self.view insertSubview:contentView atIndex:0];

contentView.contentSize = CGSizeMake(contentView.width * self.childViewControllers.count, 0);

self.contentView = contentView;

// 添加第一个控制器的view

[self scrollViewDidEndScrollingAnimation:contentView];

}

//1 待支付

- (IBAction)toBePaid:(id)sender {

NSLog(@"点击了待支付按钮");

self.orangeView1.hidden = NO;

self.orangeView2.hidden = YES;

self.orangeView3.hidden = YES;

self.orangeView4.hidden = YES;

CGFloat offsetX = 0 * self.contentsScrollView.frame.size.width;

CGPoint offset = CGPointMake(offsetX, self.contentsScrollView.contentOffset.y);

// 设置偏移量

[self.contentsScrollView setContentOffset:offset animated:YES];

self.tobePaidBtn.selected = YES;

self.toBeShippedBtn.selected = NO;

self.receiptOfGoodsBtn.selected = NO;

self.myOrderBtn.selected = NO;

}

/** 2待发货*/

//toBeShipped

- (IBAction)toBeShipped:(id)sender {

NSLog(@"点击了代发货");

self.orangeView1.hidden = YES;

self.orangeView2.hidden = NO;

self.orangeView3.hidden = YES;

self.orangeView4.hidden = YES;

CGFloat offsetX = 1 * self.contentsScrollView.frame.size.width;

CGPoint offset = CGPointMake(offsetX, self.contentsScrollView.contentOffset.y);

// 设置偏移量

[self.contentsScrollView setContentOffset:offset animated:YES];

self.tobePaidBtn.selected = NO;

self.toBeShippedBtn.selected = YES;

self.receiptOfGoodsBtn.selected = NO;

self.myOrderBtn.selected = NO;

}

/** 3待收货*/

//receiptOfGoods

- (IBAction)receiptOfGoods:(id)sender {

NSLog(@"点击了待收货按钮");

self.orangeView1.hidden = YES;

self.orangeView2.hidden = YES;

self.orangeView3.hidden = NO;

self.orangeView4.hidden = YES;

self.tobePaidBtn.selected = NO;

self.toBeShippedBtn.selected = NO;

self.receiptOfGoodsBtn.selected = YES;

self.myOrderBtn.selected = NO;

CGFloat offsetX = 2 * self.contentsScrollView.frame.size.width;

CGPoint offset = CGPointMake(offsetX, self.contentsScrollView.contentOffset.y);

// 设置偏移量

[self.contentsScrollView setContentOffset:offset animated:YES];

}

/*4*我的订单*/

//myOrder

- (IBAction)myOrder:(id)sender {

NSLog(@"点击了我的订单按钮");

self.orangeView1.hidden = YES;

self.orangeView2.hidden = YES;

self.orangeView3.hidden = YES;

self.orangeView4.hidden = NO;

CGFloat offsetX = 3 * self.contentsScrollView.frame.size.width;

CGPoint offset = CGPointMake(offsetX, self.contentsScrollView.contentOffset.y);

// 设置偏移量

[self.contentsScrollView setContentOffset:offset animated:YES];

self.tobePaidBtn.selected = NO;

self.toBeShippedBtn.selected = NO;

self.receiptOfGoodsBtn.selected = NO;

self.myOrderBtn.selected = YES;

}

#pragma mark - <UIScrollViewDelegate> Scrollview的代理方法

/**

*  在scrollView动画结束时调用(添加子控制器的view到self.contentsScrollView)

*  self.contentsScrollView == scrollView

*  用户手动触发的动画结束,不会调用这个方法

*/

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView

{

// 当前的索引

NSInteger index = scrollView.contentOffset.x / scrollView.width;

// 取出子控制器

UIViewController *vc = self.childViewControllers[index];

vc.view.x = scrollView.contentOffset.x;

vc.view.y = 0; // 设置控制器view的y值为0(默认是20)

vc.view.height = scrollView.height; // 设置控制器view的height值为整个屏幕的高度(默认是比屏幕高度少个20)

[scrollView addSubview:vc.view];

}

/**

*  当scrollView停止滚动时调用这个方法(用户手动触发的动画停止,会调用这个方法)

*/

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

[self scrollViewDidEndScrollingAnimation:scrollView];

// 点击按钮

NSInteger index = scrollView.contentOffset.x / scrollView.width;

[self titleClick:self.titlesView.subviews[index]];

}

- (void)dealloc

{

}

/**

*  SVProgressHUD 消失方法

*

*  @return

*/

- (void)dismiss{

[SVProgressHUD dismiss];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

if (buttonIndex == 1) {

NSString * str = [NSString stringWithFormat:@"telprompt://%@",self.phoneNo];

NSURL * url = [NSURL URLWithString:str];

[[UIApplication sharedApplication] openURL:url];

}

}

@end

VTMagic的使用的更多相关文章

  1. VTMagic 的使用介绍

    VTMagic 有很多开发者曾尝试模仿写出类似网易.腾讯等应用的菜单分页组件,但遍观其设计,大多都比较粗糙,不利于后续维护和扩展.琢磨良久,最终决定开源这个耗时近两年打磨而成的框架,以便大家可以快速实 ...

  2. 开源框架VTMagic的使用介绍

    VTMagic 有很多开发者曾尝试模仿写出类似网易.腾讯等应用的菜单分页组件,但遍观其设计,大多都比较粗糙,不利于后续维护和扩展.琢磨良久,最终决定开源这个耗时近两年打磨而成的框架,以便大家可以快速实 ...

  3. 深度解析开发项目之 02 - 使用VTMagic实现左右滑动的列表页

    深度解析开发项目之 02 - 使用VTMagic实现左右滑动的列表页 实现效果: 01 - 导入头文件 02 - 遵守代理协议 03 - 声明控制器的属性 04 - 设置声明属性的frame 05 - ...

  4. iOS比较常用的第三方及实例(不断更新中)

    把平时看到或项目用到的一些插件进行整理,文章后面分享一些不错的实例,若你有其它的插件欢迎分享,不断的进行更新: 一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com ...

  5. addChildViewController相关api深入剖析

    注:本文根据个人的实践和理解写成,若有不当之处欢迎斧正和探讨! addChildViewController是一个从iOS5开始支持的api接口,相关的一系列的接口是用来处理viewcontrolle ...

  6. 李洪强iOS开发之后使用纯代码实现横向滚动的UIScrollView

    李洪强iOS开发之后使用纯代码实现横向滚动的UIScrollView (VTmagic是一个实现左右滚动的控制器的框架,也可以实现此功能) 实现的效果:  01 - 创建四个控制器 02 - 定义需要 ...

  7. xxx app 项目问题解决一览

    前话:作为人生旅途中的小记录 不同账号玩法限制       解决 <vn_rule>x</vn_rule> 6.调整下注筹码 **** 解决 不同账号的玩法限制    **** ...

  8. iOS开发常用第三方开源框架 持续更新中...

    键盘管理 TPKeyboardAvoiding IQKeyboardManager(1.2.8) 弹窗HUD MBProgressHUD(0.9.2) SVProgressHUD UIView+Toa ...

  9. iOS 热门高效开源库集锦,收藏备用

    一.推荐使用的第三方库 1:基于响应式编程思想的ReactiveCocoa 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:iOS解耦与组件化开 ...

随机推荐

  1. CQOI2018 九连环 打表找规律 fft快速傅里叶变换

    题面: CQOI2018九连环 分析: 个人认为这道题没有什么价值,纯粹是为了考算法而考算法. 对于小数据我们可以直接爆搜打表,打表出来我们可以观察规律. f[1~10]: 1 2 5 10 21 4 ...

  2. Openjudge-4132-四则运算表达式求值

    这一题我们可以通过递归求解,首先我们可以把一个表达式分为三部分,分别是: (1)表达式 :项.加减 (2)项:因子.乘除 (3)因子:数.()表达式 这三项构成了递归的关系,我们可以看到,要求一个表达 ...

  3. 网络设置命令--ifconfig.setup

    ifconfig命令 作用:用于显示以及设置当前活动网卡信息 一.  显示当前活动网卡信息 ifconfig 从上面可以看到当前主要有2块活动网卡,eth0:代表当前本地真实网卡 lo:代表回访网卡, ...

  4. 利用system-config-kickstart实现半自动化安装

    老司机开车了… 上车请坐稳… centos7系统 首先确认已经安装了system-config-kickstart包,如果没有安装就yum install system-config-kickstar ...

  5. Python 装饰器 property() 函数

    描述:property() 函数的作用是在新式类中返回属性值. @property 装饰器简单理解就是负责把一个方法变成属性调用 下面理解property()方法语法: class property( ...

  6. [工具]Visual Studio

    1,Tab键的使用: 如不说有这样的代码:public Member member { get; set; } 当我们编辑完Member后,按一下Tab键,就能够将光标锁定到member上,等待键盘输 ...

  7. JSP菜鸟之困

    我一直想把java一套系统学好... 之前寒假学了android......feel good 大四又把jsp补习了一边.....85 但是苦于没有做过实例..... 暑假学PS之间想恶补一下jsp. ...

  8. python基础——2(基本数据类型及运算符)

    目录 为何数据要区分类型? 一.数字类型 1.整型int 2.浮点型float 二.字符串str 三.列表类型list 四.字典类型 五.布尔类型 运算符的介绍 一.算术运算符 二.比较运算符 三.赋 ...

  9. 3. express 框架使用 vue框架 weiUI

    express 1. 安装 npm install express --save 2. 创建项目 vue js 安装Vuejs vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue- ...

  10. python014 Python3 迭代器与生成器

    Python3 迭代器与生成器迭代器迭代是Python最强大的功能之一,是访问集合元素的一种方式..迭代器是一个可以记住遍历的位置的对象.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结 ...