Created
March 15, 2014 14:12
-
-
Save edom18/9567919 to your computer and use it in GitHub Desktop.
[Objective-C] UIViewControllerの回転を自力でやる ref: http://qiita.com/edo_m18/items/e312667396f3b49b1dbe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; | |
UIWindow *window = nil; | |
if ([appDelegate respondsToSelector:@selector(window)]) { | |
window = [appDelegate window]; | |
} | |
else { | |
window = [[UIApplication sharedApplication] keyWindow]; | |
} | |
CustomViewController *cvc = [[CustomViewController alloc] init]; | |
[window addSubview:cvc.view]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CustomViewController側 | |
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration | |
{ | |
[UIView animateWithDuration:duration | |
animations:^{ | |
CGRect frame = self.coverView.frame; | |
frame.size.width = self.view.bounds.size.width; | |
frame.size.height = self.view.bounds.size.height; | |
self.coverView.frame = frame; | |
self.coverView.center = self.view.center; | |
switch (toInterfaceOrientation) { | |
// 通常の状態 | |
case UIInterfaceOrientationPortrait: { | |
self.coverView.transform = CGAffineTransformMakeRotation(0); | |
break; | |
} | |
// デバイスの左側が上の状態 | |
case UIInterfaceOrientationLandscapeLeft: { | |
self.coverView.transform = CGAffineTransformMakeRotation(-M_PI / 2); | |
break; | |
} | |
// デバイスの右側が上の状態 | |
case UIInterfaceOrientationLandscapeRight: { | |
self.coverView.transform = CGAffineTransformMakeRotation(M_PI / 2); | |
break; | |
} | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment