Я понимаю, что есть много вопросов, связанных с этой проблемой, однако я не нашел того, что решает мою проблему.Проблема с ориентацией на iPad/iPhone
Для начала, я поставил этот код в моем 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 после изменения ориентации
Что я здесь делаю неправильно? Я не могу понять, любая помощь будет очень признательна. Заранее спасибо. ** EDIT: Новый код ниже ** Хорошо. Моя проблема в том, что представление правильно загружается в ландшафт, оно просто боком. Таким образом, пейзаж пейзаж загружается, только боком. Мой пересмотренный код, основанный на @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]; 'stuff и полная функция' - (void) orientationChanged: (NSNotification *) object'. Использование UIInterfaceOrientationLandscapeLeft и UIInterfaceOrientationLandscapeRight Дополнительная информация, чтобы проверить, работает ли функция, как ожидается, изменить цвет в инструкции if вместо установки другого UIView. – Seega
Не повезло на моем конце. Я установил его, как объяснил, и ввел точки останова в функции orientationChanged, он не называется вообще. –
Удалите проклятую ориентацию. Изменено: ВАМ НЕ НУЖНО ЭТО !!!! просто использовать '- (недействительными) willRotateToInterfaceOrientation: (UIInterfaceOrientation) Продолжительность toInterfaceOrientation: (NSTimeInterval) Продолжительность { , если (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { self.view = self.landscapeView; } прочее { self.view = self.portraitView; } } ' – Seega