iPhoneã¢ããªã§ç¸¦ç»é¢ã横ã«ããæã«å·¦ä¸ãåºæºã«ç¸¦ç»é¢ããã£ããããã¦è¡¨ç¤ºããã«ã¯?
iPhoneã¢ããªã§ç¸¦ç»é¢ã横ã¢ã¼ãã«ããæ、å¤ãã®å ´åã¯èªåãªãµã¤ãºãçºçããã®ã§ããã«ãããã¦åã¬ã¤ã¢ã¦ãããå¦çãããã ãã。ãã 、åã¬ã¤ã¢ã¦ãã¯çµæ§é¢åã 。
åã«ç¸¦ç»é¢ã横ã¢ã¼ãæã«ãã£ããããã¦è¡¨ç¤ºããããã ããªã、åã¬ã¤ã¢ã¦ãã使ããã«CGAffineTransformã使ã£ã¦ã¹ã±ã¼ãªã³ã°ããã¨ãã。
ä¸è¨ã®ãããªã³ã¼ããèªåã®ViewControllerã«è¿½å ãã。
ãã ã、CGAffineTransformMakeScaleã使ãã«ã¯CoreGraphics.frameworkã追å ãã¦ããå¿ è¦ããã。
「追å 」>「æ¢åã®ãã¬ã¼ã ã¯ã¼ã¯」ã§CoreGraphics.frameworkã®åè£ãåºã¦ããªãã£ãã®ã§、å·¦ä¸ã®「ãã®ä»ã追å 」ãã¿ã³ããä¸è¨ã®ãã©ã«ããç´æ¥æå®ãã¦è¿½å ãã。
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/System/Library/Frameworks/CoreGraphics.framework
ãããã¼ãã¡ã¤ã«ãã¤ã³ã¯ã«ã¼ãããªãã¦ãã³ã³ãã¤ã«ã§ããã®ã§、ç¹ã«ãããã¼ã®ã¤ã³ã¯ã«ã¼ãã¯å¿ è¦ã¯ãªãããã 。
åã«ç¸¦ç»é¢ã横ã¢ã¼ãæã«ãã£ããããã¦è¡¨ç¤ºããããã ããªã、åã¬ã¤ã¢ã¦ãã使ããã«CGAffineTransformã使ã£ã¦ã¹ã±ã¼ãªã³ã°ããã¨ãã。
ä¸è¨ã®ãããªã³ã¼ããèªåã®ViewControllerã«è¿½å ãã。
/** * * ããããå¤æ´ãããã¨ããããã¤ã¹ã®åãã許å¯ãã *(ããããªãã¨iPhoneãå転ããã¦ãç»é¢ã®åããå¤ãããªã) * */ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { NSLog(@"ããã¤ã¹ã®åãã¯ã©ã®æ¹åã§ãå¤æ´ãã¦ãã!"); return YES; } /** * * ããã¤ã¹ã®åãå¤æ´(å転)éå§ * */ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)_toInterfaceOrientation duration:(NSTimeInterval)duration { //toInterfaceOrientationãä¿å toInterfaceOrientation = _toInterfaceOrientation; if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { NSLog(@"ããã¤ã¹ã®åãå¤æ´éå§:縦ã¸"); targetView.transform = CGAffineTransformMakeScale(1.0, 1.0); } else { NSLog(@"ããã¤ã¹ã®åãå¤æ´éå§:横ã¸"); // 300(横ã¢ã¼ãæã®é«ã) / 460(縦ã¢ã¼ãæã®é«ã) = 0.652 targetView..transform = CGAffineTransformMakeScale(0.652, 0.652); } //ã¹ã±ã¼ãªã³ã°ã§å·¦ä¸ã®ä½ç½®ããããã®ã§、ãããã«ãã¦ã(0, 0)座æ¨ã«ç§»åããã CGRect frame = targetView.frame; frame.origin.x = 0; frame.origin.y = 0; targetView.frame = frame; } /** * * ããã¤ã¹ã®åãå¤æ´(å転)å®äº * */ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { //fromInterfaceOrientationã ãã§ã¯ç¸¦ã«ãªã£ãã®ã横ã«ãªã£ãã®ãå¤æåºæ¥ãªãã®ã§ //ä¿åãã¦ãããtoInterfaceOrientationã使ã£ã¦å¤æãã if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { NSLog(@"ããã¤ã¹ã®åãå¤æ´å®äº:縦"); } else { NSLog(@"ããã¤ã¹ã®åãå¤æ´å®äº:横"); } }
ãã ã、CGAffineTransformMakeScaleã使ãã«ã¯CoreGraphics.frameworkã追å ãã¦ããå¿ è¦ããã。
「追å 」>「æ¢åã®ãã¬ã¼ã ã¯ã¼ã¯」ã§CoreGraphics.frameworkã®åè£ãåºã¦ããªãã£ãã®ã§、å·¦ä¸ã®「ãã®ä»ã追å 」ãã¿ã³ããä¸è¨ã®ãã©ã«ããç´æ¥æå®ãã¦è¿½å ãã。
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/System/Library/Frameworks/CoreGraphics.framework
ãããã¼ãã¡ã¤ã«ãã¤ã³ã¯ã«ã¼ãããªãã¦ãã³ã³ãã¤ã«ã§ããã®ã§、ç¹ã«ãããã¼ã®ã¤ã³ã¯ã«ã¼ãã¯å¿ è¦ã¯ãªãããã 。
ããããTipsãè²ã ç´¹ä»ããã¦ããã¨å©ããã¾ã。
è¿ä¿¡åé¤