2014-01-03 7 views
1

Я пытаюсь добиться следующего:Изменение файла XIb представил на основе ротации устройств в прошивкой

У меня есть два NIB файлов, один в портретном и один в пейзаж с именем WHMainViewController и WHMainLandscapeView соответственно.

У меня есть один UIViewController с именем WHMainViewController.

Я хотел бы представить WHMainViewController, когда в портретном виде и WHMainLandscapeView, когда в альбомном режиме.

Я смотрел в эти функции:

-(void)orientationChanged:(NSNotification *)object{ UIDeviceOrientation deviceOrientation = [[object object] orientation]; 

if (deviceOrientation == UIInterfaceOrientationPortrait) { 
} 
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation == UIInterfaceOrientationLandscapeRight) { 
} 

Как я должен выполнять их, хотя?

ответ

0

Этот сайт предоставляет отличный учебник по этому вопросу: http://www.theappcodeblog.com/2011/03/30/orientation-change-tutorial-change-the-view-when-the-orientation-changes/

Установив два UIViews в XIb из WHMainViewController.

Затем подключите два устройства IBOutlets двумя двумя видами с одним именем portraitView, а другой - как LandscapeView.

Когда устройство вращается, обновить вид соответственно установив

self.view = self.portraitView; 

или

self.view = self.landscapeView; 
0
-(void)orientationChanged:(NSNotification *)object{ UIDeviceOrientation deviceOrientation = [[object object] orientation]; 

if (deviceOrientation == UIInterfaceOrientationPortrait) { 
    WHMainViewController *VC = [[WHMainViewController alloc]initWithNibName:@"WHMainViewController" bundle:nil]; 
    [self.navigationController pushViewController:VC animated:YES]; 
} 
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation == UIInterfaceOrientationLandscapeRight) 
{ 
    WHMainViewController *VC = [[WHMainViewController alloc]initWithNibName:@"WHMainLandscapeView" bundle:nil]; 
    [self.navigationController pushViewController:VC animated:YES]; 
} 
+1

Хм .. Это не похоже на работу, так как мне нужно, чтобы иметь возможность загружать пейзаж или портретный нить с одного вида при каждом повороте устройства. Я хочу переключать представления, а не наводить новые виды на исходный контроллер представления. – wayway

Смежные вопросы