2011-05-11 40 views
0

可能重複:
How to force a screen orientation in specific view controllers?iphone進行定向

你好

我想設置一個特定視圖我怎麼能做到這一點的方向。並且身體有這樣的例子。我使用的

-(void)onUIDeviceOrientationDidChangeNotification:(NSNotification*)notification{ 
    UIViewController *tvc = self.navigationController.topViewController; 
    UIDeviceOrientation orientation = [[ UIDevice currentDevice ] orientation ]; 
    tabBarController.view.hidden = YES; 
    // only switch if we need to (seem to get multiple notifications on device) 
    if(orientation != [[ UIApplication sharedApplication ] statusBarOrientation ]){ 
     if([ tvc shouldAutorotateToInterfaceOrientation: orientation ]){ 
      [ self rotateInterfaceToOrientation: orientation ]; 
     } 
    } 
} 

但它所做的是整個應用程序,我想只有在一個屏幕上完成,所以請回復 謝謝

+0

你想爲你的應用程序應用單一的方向? – ajay 2011-05-11 07:37:07

+0

重複的http://stackoverflow.com/questions/314382/how-to-force-a-screen-orientation-in-specific-view-controllers,http://stackoverflow.com/questions/3686303/uiviewcontroller-rotating - 問題和http://stackoverflow.com/questions/5297103/how-to-set-screen-orientation-like-landscape-view-programmaticaly-in-iphone – 2011-05-11 06:57:00

回答

0

放在詳細視圖控制器上

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

這是爲其他人你可以做像明智

0
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    // Over ride this method in your required view controller to display only in the necessary orientation 
} 
0

添加這個方法在你的類

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    // Over ride this method in your required view controller to display only in the necessary orientation 
    return YES; 
} 
+0

避免重複的答案..... – visakh7 2011-05-11 06:52:57