This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 336
2.3 Custom Container View Controller
yuki tamazawa edited this page Sep 3, 2013
·
4 revisions
UINavigationController Class Reference | View Controller Programming Guide for iOS
iOS 5 から UIViewController の property に childViewControllers が追加され、UINavigationController や UITabBarController のようなコンテナを自作できるようになりました。
UIViewController の view を addSubView するだけでは呼び出されない以下のメソッドが適切に呼び出される点が利点です。
- viewWillAppear:
- viewDidAppear:
- viewWillDisappear:
- viewDidDisappear:
- willRotateToInterfaceOrientation:duration:
- willAnimateRotationToInterfaceOrientation:duration:
- didRotateFromInterfaceOrientation:
自作コンテナを作ってみましょう
MixiViewController.m
#import "MixiViewController.h"
#import "MixiFirstViewController.h"
#import "MixiSecondViewController.h"
@interface MixiViewController ()
@property (weak, nonatomic) IBOutlet UIView *dummyView;
- (IBAction)pressFirstButton:(id)sender;
- (IBAction)pressSecondButton:(id)sender;
@end
@implementation MixiViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
MixiFirstViewController *fvc = [[MixiFirstViewController alloc] init];
[self addChildViewController:fvc];
fvc.view.frame = _dummyView.frame;
[self.view addSubview:fvc.view];
[fvc didMoveToParentViewController:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)transitionFromViewController:(UIViewController *)fromViewController
toViewController:(UIViewController *)toViewController
{
[fromViewController willMoveToParentViewController:nil];
[self addChildViewController:toViewController];
toViewController.view.frame = CGRectMake(0, -_dummyView.frame.size.height, _dummyView.frame.size.width, _dummyView.frame.size.height);
[self transitionFromViewController:fromViewController
toViewController:toViewController
duration:0.5
options:0
animations:^{
toViewController.view.frame = fromViewController.view.frame;
fromViewController.view.frame = CGRectMake(0, 50, _dummyView.frame.size.width, _dummyView.frame.size.height);
} completion:^(BOOL finished) {
[fromViewController removeFromParentViewController];
[toViewController didMoveToParentViewController:self];
}];
}
- (IBAction)pressFirstButton:(id)sender
{
UIViewController *currentVC = self.childViewControllers[0];
MixiFirstViewController *newVC = [[MixiFirstViewController alloc] init];
[self transitionFromViewController:currentVC toViewController:newVC];
}
- (IBAction)pressSecondButton:(id)sender
{
UIViewController *currentVC = self.childViewControllers[0];
MixiSecondViewController *newVC = [[MixiSecondViewController alloc] init];
[self transitionFromViewController:currentVC toViewController:newVC];
}
@end
MixiViewController.xib
はじめに
-
導入
-
1.3 UIViewController1 UIViewController のカスタマイズ(xib, autoresizing)
-
UIKit 1 - container, rotate-
-
UIKit 2- UIView -
-
UIKit 3 - table view -
-
UIKit 4 - image and text -
-
ネットワーク処理
-
ローカルキャッシュと通知
-
Blocks, GCD
-
設計とデザインパターン
-
開発ツール
-
テスト
-
In-App Purchase
-
付録