注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

熊猫正正的博客

熊猫正正的天空

 
 
 

日志

 
 

View Switcher的实现  

2013-04-27 23:46:04|  分类: ios开发 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
今天实现了一个View Switcher多视图的例子,能过一个SwitcherViewController控制视图的切换,代码如下:

#import <UIKit/UIKit.h>

@class BIDSwitchViewController;


@interface BIDAppDelegate : UIResponder <UIApplicationDelegate>


@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) BIDSwitchViewController *switchViewController;


@end


---------------------


#import "BIDAppDelegate.h"

#import "BIDSwitchViewController.h"


@implementation BIDAppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.switchViewController = [[BIDSwitchViewController alloc] initWithNibName:@"SwitchView" bundle:nil];

    UIView *switchView = self.switchViewController.view;

    CGRect switchViewFrame = switchView.frame;

    switchViewFrame.origin.y += [UIApplication sharedApplication].statusBarFrame.size.height;

    switchView.frame = switchViewFrame;

    [self.window addSubview:switchView];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    return YES;

}



--------------------

#import <UIKit/UIKit.h>

@class BIDYellowViewController;

@class BIDBlueViewController;


@interface BIDSwitchViewController : UIViewController


@property (strong, nonatomic) BIDYellowViewController *yellowViewController;

@property (strong, nonatomic) BIDBlueViewController *blueViewController;


@end


--------------------

#import "BIDSwitchViewController.h"

#import "BIDYellowViewController.h"

#import "BIDBlueViewController.h"


@interface BIDSwitchViewController ()


@end


@implementation BIDSwitchViewController

@synthesize yellowViewController;

@synthesize blueViewController;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view.

    self.blueViewController = [[BIDBlueViewController alloc]

                               initWithNibName:@"BlueView" bundle:nil];

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

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

    if (self.blueViewController.view.subviews == nil)

    {

        self.blueViewController = nil;

    }

    else

    {

        self.yellowViewController = nil;

    }

}


- (IBAction) switchView: (id) sender

{

    [UIView beginAnimations:@"View Flip" context:nil];

    [UIView setAnimationDuration:3.25];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    if (self.yellowViewController.view.superview == nil)

    {

        if (self.yellowViewController == nil)

        {

            self.yellowViewController = [[BIDYellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];

        }

        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

        [self.blueViewController.view removeFromSuperview];

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

    }

    else

    {

        if (self.blueViewController == nil)

        {

            self.blueViewController = [[BIDBlueViewController alloc] initWithNibName:@"BlueView" bundle:nil];

        }

        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];

        [self.yellowViewController.view removeFromSuperview];

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

    }

    [UIView commitAnimations];

}


@end


----------------------
注意:如果应用程序在启动或打开视图时崩溃,返回前面查看三个视图输出口是否均连接成功!!!

  评论这张
 
阅读(40)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017