Main Sub를 추가 하였다. MainSub가 MainWindow.xib와 연결하였다.
#import <UIKit/UIKit.h>
@class MainSub;
@interface JinSubViewAppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet MainSub *mainsub;
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) MainSub *mainsub;
@end
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window addSubview:mainsub.view]; -> 요부분 mainsub를 window에 추가 한다.
[window makeKeyAndVisible];
}
@class BlueSub;
@class RedSub;
@interface MainSub : UIViewController {
BlueSub *bluesub;
RedSub *redsub;
}
@property (retain, nonatomic)BlueSub *bluesub;
@property (retain, nonatomic)RedSub *redsub;
-(IBAction)MainSwitch:(id)sender; ->이 부분은 스위치 버튼과 연결 해주면 된다.
MainSub.m
-(IBAction)MainSwitch:(id)sender
{
if(self.redsub == nil)
{
RedSub *redcontrolsub = [[RedSub alloc]
initWithNibName:@"RedView"
bundle:nil];
self.redsub = redcontrolsub;
[redcontrolsub release];
}
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if(self.bluesub.view.superview == nil)
{
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromRight
forView:self.view cache:YES];
[bluesub viewWillAppear:YES];
[redsub viewWillAppear:YES];
[redsub viewWillDisappear:YES];
[redsub.view removeFromSuperview];
[self.view insertSubview: self.bluesub.view atIndex:0];
[redsub viewDidDisappear:YES];
[bluesub viewDidAppear:YES];
}
여기서 오해할 만한게 있는데 initWithNibName:@"RedView" 이부분이다. 스트링인데 알고 보면 View이름이다. 나머지는 RedView나 BlueView에서 간단하게 버튼 처리를 하면 된다.