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;
}
Edit- Если UIViewController
находится в пределах иерархии UINavigationController
«s
Если Ваше мнение контроллер находится в иерархии представлений UINavigationController
, методы поворота на самом деле вызываются контроллером навигации (а не контроллером) ... на мой взгляд это было реализовано смешно Apple, но вот что вы можете сделать, чтобы позволить контроллеру вида в реагировать на эти методы instead-
Создать категорию на 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 - Если UIViewController
находится в закладках UITabBarController
«s
Там же самое если ваш контроллер просмотра находится на вкладках UITabBarController
.
еще раз, создать категорию на UITabBarController
, чтобы контроллер зрения реагировать вместо:
// 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
EDIT 3
Вот также несколько ссылок на Objective-C Категории:
http://macdevelopertips.com/objective-c/objective-c-categories.html
http://mobile.tutsplus.com/tutorials/iphone/objective-c-categories/
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } – iPatel
Какая версия iOS? 'ShouldAutorotateToInterfaceOrientation:' не используется в iOS 6.0+. Для этого вам нужен метод 'supportedInterfaceOrientations'. Если вы поддерживаете 5.x и 6.x, то реализуйте оба метода. – rmaddy
http://stackoverflow.com/a/12995064/1339473 та же проблема, что и вы .. – QuokMoon