切换视图动画

#import "RootViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"

@interface RootViewController ()

@property (nonatomic, retain) SecondViewController *secondVC;
@property (nonatomic, retain) ThirdViewController *thirdVC;
@property (nonatomic, assign) BOOL isShowSecondView;

@end

@implementation RootViewController

- (void)dealloc
{
    [_secondVC release];
    [_thirdVC release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor greenColor];
    
    [self addChildViews];
    [self addButtonItem];
}

// 添加控制器显示视图
- (void)addChildViews
{
    // 创建控制器
    self.thirdVC = [[ThirdViewController alloc] init];
    // 添加子控制器
    [self addChildViewController:self.thirdVC];
    // 显示thirdVC.View
    [self.view addSubview:self.thirdVC.view];
    [_thirdVC release];
    
    // 创建控制器
    self.secondVC = [[SecondViewController alloc] init];
    // 把该控制器添加成rootVC的自控制器
    // 把secondVC.View显示出来
    
    [self addChildViewController:self.secondVC];
    [self.view addSubview:self.secondVC.view];
    [_secondVC release];
    
    // 给标识一个初值
    self.isShowSecondView = YES;
    
    
    
}

// 添加按钮
- (void)addButtonItem
{
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"切换" style:UIBarButtonItemStyleDone target:self action:@selector(actionButton:)];
    self.navigationItem.leftBarButtonItem = button;
}

// 实现切换视图
- (void)actionButton:(UIBarButtonItem *)button
{
    if (self.isShowSecondView == YES) {
        // UIView 切换的动画
        [UIView transitionFromView:self.secondVC.view toView:self.thirdVC.view duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
    } else {
        // UIView 切换的动画
        [UIView transitionFromView:self.thirdVC.view toView:self.secondVC.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil];
    }
    self.isShowSecondView = !self.isShowSecondView;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值