iPhone ã§ã¡ã¾ã¡ã¾ã²ã¼ã ä½ã£ã¦ã¿ã
ä½ãã²ã¼ã ã®å
容ã¨ããå
¨ã³ã¼ãæããã¨ã¯ããªãã
ããã¾ã§ Tips ã¨ããããä½ãéã«ããã£ããã¨ããã¦ãã¦ã¨ãæ¸ãã ãã
ã²ã¼ã ã¯è¤æ°ã®ç»é¢ããã£ã¦ãå½ç¶ã®ãã¨ãåãæ¿ãããã¿ã¤ãã«ãã²ã¼ã ç»é¢ããã«ããè¨å®ç»é¢ä½ã¯ããããæ§æããããã
ãã¡ãããç»åãé³å£°ã®äºãèãããªããç»é¢ãåãæ¿ããããªã½ã¼ã¹ã¯å¸¸ã«è§£æ¾ããã®ãæ£ãããç¹ã«é³å£°ãªã½ã¼ã¹ã¯ããªã容éãé£ãã®ã§ãç»é¢é·ç§»ã®åã«ãªã½ã¼ã¹ã解æ¾ããã
ã§ã¯ãã©ããã£ã¦ãªã½ã¼ã¹ã解æ¾ããã®ãã¨ãã話ã«ãªãããã®åã«ãã²ã¼ã ã®æ§é ãèãã¦ã¿ãã
ã¾ããã©ãã§ç»é¢ãåãæ¿ããã®ãèããã
ç»é¢ãé層åãã¦ç®¡çã§ããæåã管çç¨ã® UIViewController ãç½®ãäºãèããããããUIViewController ã®ãã¹ãã¯ãCocoa ã®ç»é¢ç®¡çã§ãQuartz ã§è¨ãã°ãã¨ã«ããç»é¢ãããã°ããç¨åº¦ã
ãªã½ã¼ã¹ãæãããã®ã§ãç»é¢åãæ¿ã㯠AppDelegate ã«ãããã¦ãã¾ãã®ããããã
ã§ããã®ã¨ãã«ç»é¢åãæ¿ãç¨ã¡ã½ãããã AppDelegate ã«çªã£è¾¼ãã©ãã
enum SceneID { SceneIDTitle, SceneIDGame, SceneIDHelp, SceneIDScore, }; /* ä¸ç¥ */ - (void)changeScene:(int)sceneId;
ã§ãå ViewController ããã¯ãAppDelegate ã«å¯¾ãã¦ãç»é¢åãæ¿ããã¼ã¨ããã¡ãã»ã¼ã¸ãéãã
ãã®ã¨ããç»é¢ï¼ã¤å
¨é¨ãAppDelegate ã¸ã®åç
§ãåå¥ã«æããã®ã¯é¢åãªã®ã§ã親ã¯ã©ã¹ãç¨æãã¦ããã
@interface ControllerBase : UIViewController { XXXXAppDelegate* gameAppDelegate; } @property(nonatomic,assign) id gameAppDelegate; @end
ï¼ ã§æ¶ãã¨ãã¨ãé¢åã ããassign ã§ããã¨æã£ããã§ããããåã²ã¼ã ã·ã¼ã³ã®ã³ã³ããã¼ã©ã§ç¶æ¿ãããç¶æ¿ä¸æ³ã
次ã«ç»é¢åãæ¿ãã®ã¡ã½ãããå®è£ ãã¦ã¿ãã
ãããã¯ãããªæãã§ã
@class ControllerBase; @interface XXXXXXAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; ControllerBase* controller; ControllerBase* oldController; } @property (nonatomic, retain) IBOutlet UIWindow *window; - (void)changeScene:(int)sceneId; @end
å®è£ ã¯ãããªæããï¼
- (ControllerBase*)sceneFactory:(int)sceneId { ControllerBase* selected = nil; switch (sceneId) { case SceneIDHelp: selected = [[HelpController alloc] initWithNibName:@"HelpController" bundle:nil]; break; case SceneIDTitle: selected = [[TitleController alloc] initWithNibName:@"TitleController" bundle:nil]; break; case SceneIDGame: selected = [[GameController alloc] init]; break; case SceneIDScore: selected = [[ScoreRecordController alloc] initWithNibName:@"ScoreRecordController" bundle:nil]; break; default: break; } [selected setGameAppDelegate:self]; return selected; } - (void)animationEnd { [oldController release]; oldController = nil; } - (void)changeScene:(int)sceneId { oldController = controller; controller = [self sceneFactory:sceneId]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [UIView setAnimationDidStopSelector:@selector(animationEnd)]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES]; [window addSubview:controller.view]; [oldController.view removeFromSuperview]; [UIView commitAnimations]; [oldController release]; }
- ã²ã¼ã ã·ã¼ã³ã®å¤æ´è¦æ±ãæ¥ãããsceneFactory ã§ã¤ã³ã¹ã¿ã³ã¹ãä½ããFactoryãã¿ã¼ã³ä¸æ³
- UIView animation ã§ç»é¢åãæ¿ããã
- animationEnd ã§ã¢ãã¡ã¼ã·ã§ã³ã®çµäºãè£è¶³ãã¦ããªã½ã¼ã¹è§£æ¾ã
ã§ããã£ããã¡ã¢ãªè§£æ¾ããã
dealloc ã¨ãå®è£
å¿ãã¡ããã¼ãã