2012-12-16 77 views
1

我有這樣的代碼,它完美的作品在iOS 5,但不能在iOS 6中,請幫助輪換代碼不能在iOS6的工作它完美地工作在iOS 5

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation 
    { 
     return (orientation != UIDeviceOrientationPortrait) && 
     (orientation != UIDeviceOrientationPortraitUpsideDown); 
    } 
+1

你看過'UIViewController'的文檔嗎?它有一整節討論支持輪換的變化。關於這個確切的話題也有許多現有的問題。請做一些搜索。 – rmaddy

+0

請參閱http://stackoverflow.com/questions/12780925/handling-rotation-in-ios6 – rmaddy

回答

2

讓試試這個: 第一內側viewDidLoad功能使用此代碼:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 
} 

然後,我是創建將接收通知的兩行代碼的功能:

- (void)orientationChanged:(NSNotification *)object{ 
    NSLog(@"orientation change"); 
    UIDeviceOrientation deviceOrientation = [[object object] orientation]; 
    if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown){ 
     if(deviceOrientation ==UIInterfaceOrientationPortrait){ 
      NSLog(@"Changed Orientation To Portrait"); 
      // Handle your view. 
     } 
    }else{ 
     if(deviceOrientation ==UIInterfaceOrientationLandscapeLeft){ 
      NSLog(@"Changed Orientation To Landscape left"); 
      // Handle your view. 
     }else{ 
      NSLog(@"Changed Orientation To Landscape right"); 
      // Handle your view. 
     } 

    } 
} 

我希望我的答案會有所幫助。乾杯。

1

在iOS6的,「shouldAutorotateToInterfaceOrientation」的方法已經過時了。嘗試在plist文件中設置方向。

+0

我在plist文件中添加了所需的定向,請在這裏嘗試另一種方法.http://stackoverflow.com/questions/12577879/shouldautorotatetointerfaceorientation-是 - 不工作 - 在-IOS-6 –

相關問題