//

//  TaskHallViewController.m

//  yybjproject

//

//  Created by bingjun on 15/10/27.

//  Copyright © 2015年 bingjun. All rights reserved.

//

#import "TaskHomeHallViewController.h"

#import "UINavigationBar+Awesome.h"

#import "HomeViewController.h"

#import "moreSensationViewController.h"

#import "SVSegmentedControl.h"

#import "TaskListViewController.h"

#import "MyTaskViewController.h"

#import "TaskHallViewController.h"

@interface TaskHomeHallViewController ()

{

MyTaskViewController *_myTaskVc;///< 红人任务控制器

moreSensationViewController *_moreSensationVc;///< 红人榜单控制器

TaskHallViewController *_shopTrolleyVc;///< 清单界面

NSInteger _segmentSelectedIndex;///< 当前segment的index

UIButton *leftBtn;///< 城市的名字

}

@end

@implementation TaskHomeHallViewController

#pragma mark - tileView的一些设置

- (void)segmentedControlChangedValue:(SVSegmentedControl*)segmentedControl {

//    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];

segmentedControl.userInteractionEnabled = NO;

if (_segmentSelectedIndex == segmentedControl.selectedSegmentIndex) {

//        [[UIApplication sharedApplication] endIgnoringInteractionEvents];

segmentedControl.userInteractionEnabled = YES;

return;

}

UIViewController *beforeVc;

switch (_segmentSelectedIndex) {

case 0:

beforeVc = _myTaskVc;

break;

case 1:

beforeVc = _shopTrolleyVc;

break;

case 2:

beforeVc = _moreSensationVc;

break;

default:

break;

}

//启动后先添加first,大儿子

switch (segmentedControl.selectedSegmentIndex) {

case 0:

{

_segmentSelectedIndex = segmentedControl.selectedSegmentIndex;

//调用addChildViewController之前会自动调用second的willMoveToParentViewController

[self addChildViewController:_myTaskVc];

[_myTaskVc.view setFrame:_myTaskVc.view.frame];

[self transitionFromViewController:beforeVc toViewController:_myTaskVc duration:1.0 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished){

//删除之前first之前手动添加的willMoveToParentViewController

[beforeVc willMoveToParentViewController:nil];

//调用removeFromParentViewController之后会自动调用first的didMoveToParentViewController

[beforeVc removeFromParentViewController];

//addChildViewController之后手动添加的didMoveToParentViewController

[_myTaskVc didMoveToParentViewController:self];

//                [[UIApplication sharedApplication] endIgnoringInteractionEvents];

segmentedControl.userInteractionEnabled = YES;

}];

break;

}

case 1:

{

_segmentSelectedIndex = segmentedControl.selectedSegmentIndex;

[self addChildViewController:_shopTrolleyVc];

[_shopTrolleyVc.view setFrame:_myTaskVc.view.frame];

[self transitionFromViewController:beforeVc toViewController:_shopTrolleyVc duration:1.0 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished){

//addChildViewController之后手动添加的didMoveToParentViewController

//删除之前first之前手动添加的willMoveToParentViewController

[beforeVc willMoveToParentViewController:nil];

//调用removeFromParentViewController之后会自动调用first的didMoveToParentViewController

[beforeVc removeFromParentViewController];

[_shopTrolleyVc didMoveToParentViewController:self];

//                [[UIApplication sharedApplication] endIgnoringInteractionEvents];

segmentedControl.userInteractionEnabled = YES;

}];

break;

}

case 2:

{

_segmentSelectedIndex = segmentedControl.selectedSegmentIndex;

[self addChildViewController:_moreSensationVc];

[_moreSensationVc.view setFrame:_myTaskVc.view.frame];

[self transitionFromViewController:beforeVc toViewController:_moreSensationVc duration:1.0 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished){

//删除之前first之前手动添加的willMoveToParentViewController

[beforeVc willMoveToParentViewController:nil];

//调用removeFromParentViewController之后会自动调用first的didMoveToParentViewController

[beforeVc removeFromParentViewController];

//addChildViewController之后手动添加的didMoveToParentViewController

[_moreSensationVc didMoveToParentViewController:self];

//                [[UIApplication sharedApplication] endIgnoringInteractionEvents];

segmentedControl.userInteractionEnabled = YES;

}];

break;

}

default:

break;

}

}

//设置titleVIew

- (void)initTitleViewOfMyTask

{

NSArray *array;

if (kDeviceWidth > 320) {

array = [NSArray arrayWithObjects:@"任  务", @"红  人", @"榜  单", nil];

}else {

array = [NSArray arrayWithObjects:@"任务", @"红人", @"榜单", nil];

}

SVSegmentedControl *yellowRC = [[SVSegmentedControl alloc] initWithSectionTitles:array];

[yellowRC addTarget:self action:@selector(segmentedControlChangedValue:) forControlEvents:UIControlEventValueChanged];

//    yellowRC.crossFadeLabelsOnDrag = YES;

yellowRC.animateToInitialSelection = YES;

yellowRC.font = [UIFont systemFontOfSize:14];

yellowRC.textColor = [UIColor whiteColor];//没有被选中的字体颜色

//    yellowRC.titleEdgeInsets = UIEdgeInsetsMake(0, 14, 0, 14);

yellowRC.height = 30;

yellowRC.backgroundTintColor = YSRedProjectColor;//没有被选中的背景颜色

//  yellowRC.textShadowColor = [UIColor whiteColor];

[yellowRC setSelectedSegmentIndex:0 animated:NO];

yellowRC.thumb.tintColor = [UIColor whiteColor];//选中的背景颜色

yellowRC.thumb.textColor = YSRedProjectColor;//选中的title字体颜色

yellowRC.thumb.textShadowColor = [UIColor whiteColor];

//    yellowRC.thumb.textShadowOffset = CGSizeMake(0, 1);

yellowRC.thumb.gradientIntensity = 0.05;

yellowRC.center = CGPointMake(180, 100);

self.navigationItem.titleView = yellowRC;

_segmentSelectedIndex = 0;

}

//添加右上角按钮

- (void)addLeftBarButtonItemAction

{

CGFloat kLefyViewWidth;

CGFloat kImageViewWidth;

CGFloat kTitleViewWidth;

CGFloat kTitleFontSize;

if (kDeviceWidth > 320) {

kLefyViewWidth = 75.0f;

kImageViewWidth = 14.0f;

kTitleViewWidth = 60.0f;

kTitleFontSize = 13.0f;

}else {

kLefyViewWidth = 60.0f;

kImageViewWidth = 10.0f;

kTitleViewWidth = 50.0f;

kTitleFontSize = 10.0f;

}

UIView *rightItemView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kLefyViewWidth, 34.0f)];

rightItemView.backgroundColor = [UIColor clearColor];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, (34 - kImageViewWidth) / 2.0f, kImageViewWidth, kImageViewWidth)];

imageView.image = [UIImage imageNamed:@"positionIcon.png"];

imageView.contentMode = UIViewContentModeScaleAspectFit;

[rightItemView addSubview:imageView];

leftBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];

User *user = [[User instance] getUserInformation];

if (user.userCity && ![user.userCity isKindOfClass:[NSNull class]]) {

[leftBtn setTitle:user.userCity forState:UIControlStateNormal];

}else {

[leftBtn setTitle:@"暂无" forState:UIControlStateNormal];

}

leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

leftBtn.frame=CGRectMake(kImageViewWidth, 0.0f, kTitleViewWidth, 34.0f);

[leftBtn.titleLabel setFont:[UIFont systemFontOfSize:kTitleFontSize]];

[rightItemView addSubview:leftBtn];

UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:rightItemView];

self.navigationItem.leftBarButtonItem = leftItem;

}

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view from its nib.

[self addLeftBarButtonItemAction];

//设置导航栏颜色

self.navigationController.navigationBar.translucent = YES;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {

self.edgesForExtendedLayout = UIRectEdgeNone;

}

[self.navigationController.navigationBar lt_setBackgroundColor:YSRedProjectColor];

HomeViewController *home = [HomeViewController singleton];

//    HomeViewController *home = self.navigationController.tabBarController;

[home showTabBar:YES];

//设置titleView

[self initTitleViewOfMyTask];

//生俩儿子

_myTaskVc = [[MyTaskViewController alloc] initWithNibName:@"MyTaskViewController" bundle:nil];

_moreSensationVc = [[moreSensationViewController alloc] initWithNibName:nil bundle:nil];

_shopTrolleyVc = [[TaskHallViewController alloc] initWithNibName:@"TaskHallViewController" bundle:nil];

_shopTrolleyVc.isNeedShowSearchFlag = YES;

//启动后先添加first,大儿子

[self addChildViewController:_myTaskVc];

[_myTaskVc.view setFrame:self.view.frame];

[self.view addSubview:_myTaskVc.view];

[_myTaskVc didMoveToParentViewController:self];

[[NSNotificationCenter defaultCenter]addObserver:self

selector:@selector(update_CityName:)

name:Update_CityName object:nil];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/

- (void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

HomeViewController *home = [HomeViewController singleton];

[home showTabBar:NO];

}

- (void)viewWillDisappear:(BOOL)animated

{

[super viewWillDisappear:animated];

HomeViewController *home = [HomeViewController singleton];

[home hideTabBar:NO];

}

- (void)update_CityName:(NSNotification *)notification

{

NSString *cityName = notification.object;

[leftBtn setTitle:cityName forState:UIControlStateNormal];

}

@end

UIViewController添加子控制器(addChildViewController)的更多相关文章

  1. 解决UIViewController中添加子控制器viewWillAppear不调用问题

    问题描述: 我在UICollectionViewController中添加子控制器数组, 并在cellForItem中把子控制器数组中对应的控制器对应的view添加到了UICollectionView ...

  2. ViewController添加子控制器 并且弹出

    /** *  初始化子控制器 */ - (void)setupChildVcs { for (int i = 0; i<6; i++) { UIViewController *vc = [[UI ...

  3. IOS UITabBarController(控制器)的子控制器

    UITabBarController的简单使用 ● UITabBarController的使用步骤 ➢ 初始化UITabBarController ➢ 设置UIWindow的rootViewContr ...

  4. AJ学IOS 之微博项目实战(1)微博主框架-子控制器的添加

    AJ分享,必须精品 一:简单介绍 这是新浪微博的iOS端项目,来自于黑马的一个实战项目. 主要分成五大模块,本次全部运用纯代码实现,其中会用到很多前面学过得内容,如果有的地方有重复的知识点,说明这个知 ...

  5. iOS不得姐项目--精华模块上拉下拉的注意事项,日期显示,重构子控制器,计算cell的高度(只计算一次),图片帖子的显示

    一.上拉下拉注意事项 使用MJRefresh中的上拉控件自动设置透明 当请求下页数据通过page的时候,注意的是上拉加载更多数据失败的问题,下拉加载数据失败了,页数应该还原.或者是请求成功的时候再将页 ...

  6. iOS开发-在表单元中添加子视图

    #import <UIKit/UIKit.h> @interface NameAndColorCellTableViewCell : UITableViewCell @property(c ...

  7. Ext JS添加子组件的误区

    经常会有人问我,为什么我的Grid不能岁窗口的变得而自动调整.了解后,发现很多人都习惯在渲染子组件的时候将Gird渲染到容器内的一个div里,而这正是问题的所在. 在Ext JS的布局系统中,能控制到 ...

  8. IOS 拦截所有push进来的子控制器

    /** * 能拦截所有push进来的子控制器 */ - (void)pushViewController:(UIViewController *)viewController animated:(BO ...

  9. Ext.js添加子组件

    Ext框架提供了很多api,对于不熟悉的人来说,api的释义有时不够明了.最近碰到了添加子组件的需求,特记录下来. 1. 例如,有一个窗体组件: 现在要为其添加一个字段“学校分类”,变成如下所示: 示 ...

随机推荐

  1. C++调用C中编译过的函数要加extern "C"

    C++语言支持函数重载,C语言不支持函数重载.函数被C++编译后在库中的名字与C语言的不同.假设某个C 函数的声明如下:void foo(int x, int y);该函数被C 编译器编译后在库中的名 ...

  2. ARPG游戏技能系统设计

    ARPG游戏的技能的前端表现, 主要指的是人物动作和特效表现, 从普遍意义上讲,大致可以分为三个阶段:起手.飞行.碰撞(爆炸). [特效可见性判断] 1.[attacker & victim] ...

  3. C++从键盘输入文件结束符

            当我们使用一个istream对象作为条件时,其效果是检测流的状态.如果流是有效的,即流未遇到错误,那么检测成功.当遇到文件结束符,或遇到一个无效输入时(例如需要将输入读到一个int变量 ...

  4. call(京基填小票拍照片)

    同事的写的函数结构,先是几个函数表达式var a = function(){},里面再是函数声明function a(){} 里面用了好多call,网上搜了一下call的用途: 1. http://w ...

  5. Scrum团队成立,阅读《构建之法》第6~7章,并参考以下链接,发布读后感、提出问题、并简要说明你对Scrum的理解

    Scrum团队成立:  团队名称:神的孩子 团队目标:短期目标,完成O2O模式的第一个平台 团队口号:我们都不是神的孩子 团队照: 角色分配 产品负责人: 许佳仪.决定开发内容和优先级排序,最大化产品 ...

  6. linux下如何优雅的挂载一个外界设备(比如优盘)

    最近从事linux,实验室一个破服务器,能连上网,但是输入这样的命令:        yum -y install gcc yum -y install gcc-c++ ,居然说是没有这样的镜像,也罢 ...

  7. jQuery选择器介绍:基本选择器、层次选择器、过滤选择器、表单选择器

    选择器是jQuery的根基,在jQuery中,对事件处理.遍历DOM和Ajax操作都依赖于选择器.因此,如果能熟练的使用选择器,不仅能简化代码,而且可以达到事半功倍的效果.jQuery选择器完全继承了 ...

  8. C# + winserver2008 openfiledialog 写入 textbox1 中的 路径不正确

    System.IO.Path.GetFullPath(openFileDialog1.FileName);//绝对路径 System.IO.Path.GetExtension(openFileDial ...

  9. mongodb的监控与性能优化

    一.mongodb的监控 mongodb可以通过profile来监控数据,进行优化. 查看当前是否开启profile功能用命令 db.getProfilingLevel()  返回level等级,值为 ...

  10. XAML-1

    1.XAML Extension Application Marked Language,是WPF技术中专门用来设计UI的语言.XAML是从XML派生出来的,是一种声明式语言,当你看到一个标签,就是声 ...