トップ «前の日記(2012-10-10) 最新 次の日記(2012-10-13)» 編集

Cocoa練習帳

iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど

2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|04|05|06|

2012-10-11 [iOS]画面遷移(コンテナViewController)

以前のサンプルと比較しやすくするため、ビューを使った画面遷移のサンプルコードをビューコントローラのコンテナ機能を使った物に変更してみた。

TransitionViewのAppDelegate.mを以下の内容に変更。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    CGRect  screenBounds = [[UIScreen mainScreen] applicationFrame];
    CGRect  windowBounds = [[UIScreen mainScreen] bounds];
     
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
    self.containerViewController = [[UIViewController alloc] init];
    self.containerViewController.view.backgroundColor = [UIColor yellowColor];
    self.myViewController1 = [[MyViewController alloc] init];
    self.myViewController1.view.backgroundColor = [UIColor redColor];
    self.myViewController1.title = @"one";
    self.myViewController2 = [[MyViewController alloc] init];
    self.myViewController2.view.backgroundColor = [UIColor blueColor];
    self.myViewController2.title = @"two";
    
    self.window.rootViewController = self.containerViewController;
    
    /* コンテナViewControllerの子ViewControllerに登録 */
    [self.containerViewController addChildViewController:self.myViewController1];
    [self.containerViewController addChildViewController:self.myViewController2];
    
    /* 強制的に呼ぶ */
    [self.myViewController1 didMoveToParentViewController:self.containerViewController];
    [self.myViewController2 didMoveToParentViewController:self.containerViewController];
    
    /* 最初の画面を設定 */
    self.isView1 = YES;
    CGRect  frame = self.myViewController1.view.frame;
    frame.origin = CGPointMake(0.0, 0.0);
    self.myViewController1.view.frame = frame;
    self.myViewController2.view.frame = frame;
    [self.containerViewController.view addSubview:self.self.myViewController1.view];
    
    [self.window makeKeyAndVisible];
    return YES;
}
 
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (self.isView1) {
        self.isView1 = NO;
        [self.containerViewController transitionFromViewController:self.myViewController1
                                                  toViewController:self.myViewController2
                                                          duration:1.0
                                                           options:UIViewAnimationOptionTransitionCrossDissolve
                                                        animations:NULL
                                                        completion:NULL];
    }
    else {
        self.isView1 = YES;
        [self.containerViewController transitionFromViewController:self.myViewController2
                                                  toViewController:self.myViewController1
                                                          duration:1.0
                                                           options:UIViewAnimationOptionTransitionCrossDissolve
                                                        animations:NULL
                                                        completion:NULL];
    }
}

_ 【Cocoa練習帳】

http://www.bitz.co.jp/weblog/
http://ameblo.jp/bitz/(ミラー・サイト)

トップ «前の日記(2012-10-10) 最新 次の日記(2012-10-13)» 編集