ios5 多视图切换

t1ViewController.h 的内容如下:(t1ViewController是根控制器, 我这里是创建工程的时候默认的,也可以使用, self.window.rootViewController方法指定根控制器)

#import <UIKit/UIKit.h>

@interface t1ViewController : UIViewController

@property (nonatomic,retain) IBOutlet UIViewController *myview;
@property (nonatomic,retain) IBOutlet UIViewController *myview2;
- (IBAction)clickme:(id)sender;
 

@end

t1ViewController.m (文件内容如下)

#import "t1ViewController.h"
#import "yellow.h"  //uiviewcontroller内容,可以为空,但为了有效果,背景设置不同的色
#import "blue.h"  uiviewcontroller内容,可以为空,但为了有效果,背景设置不同的色


@implementation t1ViewController
@synthesize myview;
@synthesize myview2;


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}


#pragma mark - View lifecycle


- (void)viewDidLoad
{
    
    blue *blueController = [[blue alloc] initWithNibName:@"blue" bundle:nil];
self.myview2 = blueController;
[self.view insertSubview:blueController.view atIndex:0];
    yellow *yellowController = [[yellow alloc] initWithNibName:@"yellow" bundle:nil];
self.myview = yellowController;
    
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}


- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}


- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}


- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}


- (IBAction)clickme:(id)sender {  //这个action在根控制器,拖一个按钮,并关联clickme方法。
    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    UIViewController *curr = nil;
    UIViewController *going = nil;
  if(self.myview.view.superview == nil)
  {
   
      curr = myview2;
      going = myview;
  }
    else
    {
        curr = myview;
        going = myview2;
        
    }
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    [myview viewWillAppear:YES];
    [myview2 viewWillDisappear:YES];
    [myview2.view removeFromSuperview];
    [self.view insertSubview:myview.view atIndex:0];
    [myview viewDidDisappear:YES];
    [myview2 viewDidAppear:YES];
     [UIView commitAnimations];
}

@end

有问题Q我加VX:18618146379  http://blog.fendong.cc

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值