//
// Created by WDX on 15/9/23.
// Copyright (c) 2015年 WDongXu. All rights reserved.
//
#import "RootViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
@interface RootViewController ()
// 声明两个控制器
@property (nonatomic, retain)SecondViewController *secondVC;
@property (nonatomic, retain)ThirdViewController *thirdVC;
// 声明一个状态 标识是哪个view
@property (nonatomic, assign)BOOL isShowSecondView;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor blueColor];
[self addChildViews];
[self addButtonItem];
}
// 添加控制器并显示视图
- (void)addChildViews
{
// 创建控制器
self.thirdVC = [[ThirdViewController alloc]init];
// 把该控制器添加成rootVC的子控制器
[self addChildViewController:self.thirdVC];
// 显示thirdVC.view显示出来
[self.view addSubview:self.thirdVC.view];
[_thirdVC release];
// 创建控制器
self.secondVC = [[SecondViewController alloc] init];
// 把该控制器添加成 rootVC 的子控制器
[self addChildViewController:self.secondVC];
//把secondVC .view显示出来
[self.view addSubview:self.secondVC.view];
[_secondVC release];
// 被标识一个初值,一开始显示的页面
self.isShowSecondView = YES;
}
// 添加按钮
- (void)addButtonItem
{
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"转" style:(UIBarButtonItemStylePlain) target:self action:@selector(actionButton:)];
self.navigationItem.leftBarButtonItem = button;
[button release];
}
- (void)actionButton:(UIBarButtonItem *)button
{
if (_isShowSecondView == YES) {
// UIView 切换动画
[UIView transitionFromView:self.secondVC.view toView:self.thirdVC.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
}];
} else {
// 切换回来
[UIView transitionFromView:self.thirdVC.view toView:self.secondVC.view duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
}];
}
// 更改标识状态
_isShowSecondView =! _isShowSecondView;
}