Я понимаю, что есть много вопросов, связанных с этой проблемой, однако я не нашел ни одного, который решает мою проблему.
Для начала я установил этот код в свой menu.h
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES; }
Строка состояния меняется в зависимости от ориентации, но представления не вращаются и не изменяются в размере. Чтобы попытаться сузить мою проблему, я решил попробовать переключить два вида в одном .xib на основе ориентации.
- (void)viewDidLoad {
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
-(void) orientationChanged:(NSNotification *)object
{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation == UIDeviceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
}
В симуляторе iOS представление определенно меняется на определенные представления. Однако альбомный вид отображается так, как если бы он был портретным и боковым.
мой альбомный вид в IB
Мой альбомный вид в симуляторе iOS после изменения ориентации
Что я здесь делаю неправильно? Я не могу понять это, любая помощь будет принята с благодарностью. Заранее спасибо. ** РЕДАКТИРОВАТЬ: новый код ниже ** Хорошо. Моя проблема в том, что вид правильно загружается в ландшафте, он просто сбоку. Таким образом, ландшафтный вид загружается только сбоку. Мой исправленный код, основанный на @Seega:
- (void)viewDidLoad {
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
[[TTNavigator navigator] setCustomTarget:self];
[[TTNavigator navigator] setCustomAction:@selector(photoAction)];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIDeviceOrientationLandscapeLeft || toInterfaceOrientation == UIDeviceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
}
-(void) orientationChanged:(NSNotification *)object
{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation == UIDeviceOrientationLandscapeRight)
{
self.view = self.landscapeView;
}
else
{
self.view = self.portraitView;
}
}
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
и полную функцию-(void) orientationChanged:(NSNotification *)object
. Используйте дополнительные UIInterfaceOrientationLandscapeLeft и UIInterfaceOrientationLandscapeRight, чтобы проверить, работает ли функция должным образом, измените цвет в операторе if вместо установки другого UIView. - person Seega   schedule 17.04.2012- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { self.view = self.landscapeView; } else { self.view = self.portraitView; } }
- person Seega   schedule 17.04.2012