2011-12-30 78 views
1

我有一个UIViewController在横向模式显示UINavigationController纵向。当我使用模态segue连接从视图控制器获取导航控制器时,出于某种原因,视图控制器最初被强制为纵向(最初时它应该处于横向)。当我删除赛格时,事情按预期工作。使用segues自动旋转视图

期望的行为是使用从横向的界面到纵向的另一个界面的模态渐变。

任何想法这里发生了什么?或如何使其按预期工作?

回答

0

使用通知。

-(void)viewWillAppear:(BOOL) animated{ 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(receivedRotate:) name: UIDeviceOrientationDidChangeNotification object: nil]; 
} 

-(void) receivedRotate: (NSNotification*) notification 
{ 
UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation]; 
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
{ 
    [self performSegueWithIdentifier:@"/* Segue from the VCPotrait to VCLandscape*/" sender: self]; 
} 
} 

该segue应该是模态的。

+0

埃姆,我想你是误会我的问题。我想知道如何在iPhone打开模态视图控制器时强制iPhone改变方向。我已经知道如何处理由用户造成的方向。 – 2011-12-31 00:34:53

+0

我想有一个设备方向属性。这应该使您能够设置方向。 – Faser 2012-01-01 13:37:38

+0

如果您指的是UIDevice的orientation属性,那是只读的。 – 2012-01-01 19:43:25

0

你的意思是最初的导航控制器被迫纵向?

我已经完成了这与UIViewController子类,其中我有一个视图控制器在纵向方向,模式赛格视图控制器横向。关键是在讲第二控制器不自转任何方向,我不想:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
} 

你要继承的UINavigationController要能设置,我认为。

的赛格瑞在故事板定义为模态,并在第一(主持人)视图控制器代码看起来非常正常:

-(IBAction) zoomIn:(id)sender { 
    [self performSegueWithIdentifier:@"ZoomIn" sender: self]; 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([[segue identifier] isEqualToString:@"ZoomIn"]) { 
     OSZoomViewController *zoom = [segue destinationViewController]; 
     zoom.image = ...; 
     zoom.presenter = self; 
    } 
}