2012-10-08 121 views
0

当我用这个代码:不要旋转子视图

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations 
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration: (NSTimeInterval)duration { 

    if ((toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) || toInterfaceOrientation==UIInterfaceOrientationLandscapeRight) { 
    LeftLVC* vc = [[LeftLVC alloc] initWithNibName:@"LeftLVC" bundle:nil];  
    [self.navigationController pushViewController:vc animated:YES];  
    } 
} 

子视图旋转。在我的项目子视图必须保持固定的肖像。

+0

如果你不想旋转视图'return false' – Popeye

+0

你不理解我。我在主视图上使用此代码,以使子视图自动旋转。 – Daedelus

+0

也在子视图中使用相同的代码.. –

回答

0

shouldAutorotateToInterfaceOrientation:用于指定支持的方向。如果您只想支持人像模式,请执行以下操作:

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

上述方法在iOS 6.0中已弃用。改为改写supportedInterfaceOrientationspreferredInterfaceOrientationForPresentation方法。 详情请参阅Apple Documentation

willRotateToInterfaceOrientation:duration:就在用户界面开始旋转之前发送到视图控制器。在将方向从横向移动到纵向时,此方法将被调用。