2012-10-08 122 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:就在用戶界面開始旋轉之前發送到視圖控制器。在將方向從橫向移動到縱向時,此方法將被調用。