Skip to content

Instantly share code, notes, and snippets.

@edom18
Created March 15, 2014 14:12
Show Gist options
  • Save edom18/9567919 to your computer and use it in GitHub Desktop.
Save edom18/9567919 to your computer and use it in GitHub Desktop.
[Objective-C] UIViewControllerの回転を自力でやる ref: http://qiita.com/edo_m18/items/e312667396f3b49b1dbe
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];
// 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