iOS 6.0 では、新しい回転メソッドが導入され、shouldAutorotateToInterfaceOrientation:
.
iOS 6.0 より前のバージョンと iOS 6.0 以降のバージョンの両方をサポートするには、次のメソッドを実装する必要があります。
// Do as many checks as you want to allow for other orientations here for pre-iOS 6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
// You can return YES here as this still checks supportedInterfaceOrientations
// before rotating, or you can return NO to 'lock' the view in whatever it's in...
// Making sure to return the appropriate value within supportedInterfaceOrientations
- (BOOL)shouldAutorotate
{
return YES;
}
// return supported orientations, bitwised OR-ed together
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
編集-あなたがの階層UIViewController
内にある場合UINavigationController
ビュー コントローラーがUINavigationController
のビュー階層内にある場合、回転メソッドは実際には (ビュー コントローラーではなく) ナビゲーション コントローラーで呼び出されます...これは私の意見では Apple によって面白く実装されましたが、許可するためにできることは次のとおりです。代わりにこれらのメソッドに応答するView Controller-
UINavigationController
次の方法でカテゴリを作成します。
// UINavigationController+Additions.h file
@interface UINavigationController (Additions)
@end
// UINavigationController+Additions.m file
#import "UINavigationController+Additions.h"
@implementation UINavigationController (Additions)
- (BOOL)shouldAutorotate
{
return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
UIViewController *viewController = [self topViewController];
if ([viewController respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)])
{
return [viewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}
return [super shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}
- (NSUInteger)supportedInterfaceOrientations
{
UIViewController *viewController = [self topViewController];
if ([viewController respondsToSelector:@selector(supportedInterfaceOrientations)])
{
return [viewController supportedInterfaceOrientations];
}
return [super supportedInterfaceOrientations];
}
@end
EDIT 2 - あなたが aのタブUIViewController
内にある場合UITabBarController
View Controller がUITabBarController
のタブ内にある場合、同じ問題があります。
もう一度、カテゴリを on に作成して、UITabBarController
代わりに View Controller が応答できるようにします。
// UITabBarController+Additions.h file
@interface UITabBarController (Additions)
@end
// UITabBarController+Additions.m file
#import "UITabBarController+Additions.h"
@implementation UITabBarController (Additions)
- (BOOL)shouldAutorotate
{
return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
UIViewController *selectedViewController = [self selectedViewController];
if ([selectedViewController respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)])
{
return [selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}
return [super shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}
- (NSUInteger)supportedInterfaceOrientations
{
UIViewController *selectedViewController = [self selectedViewController];
if ([selectedViewController respondsToSelector:@selector(supportedInterfaceOrientations)])
{
return [selectedViewController supportedInterfaceOrientations];
}
return [super supportedInterfaceOrientations];
}
@end
編集3
Objective-C カテゴリに関するリンクもいくつかあります。
http://macdevelopertips.com/objective-c/objective-c-categories.html
http://mobile.tutsplus.com/tutorials/iphone/objective-c-categories/