IOS5基础之五-----多视图应用程序

创建一个ViewSwitcher,在模板选择时选择Empty Application。

接下来要创建视图控制器和nib文件,如图:


选中左边的View Switch command+n 出现右边的图,选择UIViewControllersubClass然后Next。


然后输入类名称。

Subclass of 视图布局和表格布局。

Taregeed for IPad  创建IPad。

with XIB for user interface 同时创建一个与此控制器相关联的nib文件。

同理可以创建BIDBlueViewController和BIDYellowController。


创建GDI




这里注意的是要Group中选中View Switch。

同理创建BlueView.xib 和Yellow.xib

修改应用程序头文件中

#import<UIKit/UIKit.h>

@classBIDSwitchViewController;

@interface BIDAppDelegate :UIResponder <UIApplicationDelegate>

@property (strong,nonatomic) UIWindow *window;

@property (strong,nonatomic)BIDSwitchViewController *switchViewController;//指向应用程序的根控制器

@end


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

{

   self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

   // Override point for customization after application launch.

    

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

   UIView *switchView=self.switchViewController.view;

    CGRect switchViewFrame=switchView.frame;

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

    switchView.frame=switchViewFrame;

    [self.windowaddSubview:switchView];

    

   self.window.backgroundColor = [UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];

   return YES;

}


修改BIDSwitchViewController.h

#import<UIKit/UIKit.h>

@classBIDYellowViewController;

@classBIDBlueViewController;


@interface BIDSwitchViewController :UIViewController

@property (strong,nonatomic)BIDYellowViewController *yellowViewController;

@property (strong ,nonatomic)BIDBlueViewController *blueViewController;

-(IBAction)switchViews:(id)sender;

@end


添加视图控制器关联
Class 原来的NSObjet 修改为如图所示。
Received Action会变成switchViews。

选择视图,在视图中拖入ToolBar并且修改按钮值为Switch View.


将Switch Views按钮关联到File's Owner,并且选择switchViews操作。File‘s Owner重新关联View,选择view。

beginAnimations:Context:接受两个参数 第一个是动画块标题,第二个是指针与此动画块关联的对象。

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];设置动画曲线

[UIView setAnimationTransition

UIViewAnimationTransitionFlipFromLeft 设置转换类型iOS提供四种装换类型

UIViewAnimationTransitionFlipFromRight

UIViewAnimationTransitionCurlUp

UIViewAnimationTransitionCurlDown                             


#import"BIDSwitchViewController.h"

#import"BIDBlueViewController.h"

#import"BIDYellowViewController.h"

@implementation BIDSwitchViewController;

@synthesize yellowViewController;

@synthesize blueViewController;


- (void)viewDidLoad

{

   self.blueViewController = [[BIDBlueViewControlleralloc]

                              initWithNibName:@"BlueView"bundle:nil];//这里覆盖了将在载入nib时调用的UIViewController方法。

    [self.viewinsertSubview:self.blueViewController.viewatIndex:0];

    [superviewDidLoad];

}


- (IBAction)switchViews:(id)sender {

    [UIViewbeginAnimations:@"View Flip"context:nil];

    [UIViewsetAnimationDuration:1.25];

    [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];

    

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

       if (self.yellowViewController ==nil) {

           self.yellowViewController =

            [[BIDYellowViewControlleralloc] initWithNibName:@"YellowView"

                                                     bundle:nil];

        }

        [UIViewsetAnimationTransition:

        UIViewAnimationTransitionFlipFromRight

                              forView:self.viewcache:YES];

        

        [self.blueViewController.viewremoveFromSuperview];

        [self.viewinsertSubview:self.yellowViewController.viewatIndex:0];

    } else {

        if (self.blueViewController ==nil) {

           self.blueViewController =

            [[BIDBlueViewControlleralloc] initWithNibName:@"BlueView"

                                                   bundle:nil];

        }

        [UIViewsetAnimationTransition:

        UIViewAnimationTransitionFlipFromLeft

                              forView:self.viewcache:YES];

        

        [self.yellowViewController.viewremoveFromSuperview];

        [self.viewinsertSubview:self.blueViewController.viewatIndex:0];

    }

    [UIViewcommitAnimations];

}


- (void)didReceiveMemoryWarning

{

   // Releases the view if it doesn't have a superview.

    [superdidReceiveMemoryWarning];  

   // Release any cached data, images, etc that aren't in use.

    

   if (self.blueViewController.view.superview == nil) {

       self.blueViewController =nil;

    } else {

       self.yellowViewController =nil;

    }

}


实现内容视图
BIDBlueViewController的头文件增加

-(IBAction)blueButtonPressed;

打开BlueView.xib 把File’s Owner的class改为BIDBlueViewController。在属性检查器中修改background为蓝色。


sattus Bar修改为None Botton Bar 修改为ToolBar。
在页面上添加一个按钮


找到按钮的连接检查器,选择Touch Up Inside 事件关联到File‘s Owner上连接blueButtonPressed方法。

这个方法也就是添加一个警告。

-(IBAction)blueButtonPressed

{

   UIAlertView *alert=[[UIAlertViewalloc] initWithTitle:@"Blue View Button Pressed"message:@"You pressed the button on the blue view"delegate:nilcancelButtonTitle:@"Yes,I did."otherButtonTitles:nil];

    [alert show];

}

上次根据Xcode3.2.5中的操作,很多地方和4.2的相差很多,再加上对xcode,不熟悉,导致这个到现在才出来,真是很惭愧。尴尬,继续努力学习!搞了一天,郁闷啊!



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值