あらかじめ[appname].plistのSupported interface orientationsを設定する必要がある。
- (void)viewDidLoad
{
[super viewDidLoad];
//iOS 4.3~5.1 回転時の呼び出しメソッドを設定
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
//iOS 4.3~5.1 回転の停止
//他のViewControllerで使用したくないときはここでキャンセルする
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
//iOS 6.0~ 回転をサポートするか
- (BOOL)shouldAutorotate
{
return YES;
}
//iOS 6.0~ 推奨される向き
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
//iOS 6.0~ サポートする向き
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
//iOS 4.3~5.1 回転をサポートするか?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
//回転時の動作
- (void)orientationChanged:(NSNotification *)notification
{
}
//回転時のアニメーションを定義
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
}
//回転前に呼び出される
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}
0 件のコメント:
コメントを投稿