创建一个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;
}
#import<UIKit/UIKit.h>
@classBIDYellowViewController;
@classBIDBlueViewController;
@interface BIDSwitchViewController :UIViewController
@property (strong,nonatomic)BIDYellowViewController *yellowViewController;
@property (strong ,nonatomic)BIDBlueViewController *blueViewController;
-(IBAction)switchViews:(id)sender;
@end
选择视图,在视图中拖入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;
}
}
-(IBAction)blueButtonPressed;
打开BlueView.xib 把File’s Owner的class改为BIDBlueViewController。在属性检查器中修改background为蓝色。
找到按钮的连接检查器,选择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,不熟悉,导致这个到现在才出来,真是很惭愧。,继续努力学习!搞了一天,郁闷啊!