2010-05-06 50 views
1

我的iPad應用程序中的自動旋轉接口有問題。我有一個名爲Switcher類觀察界面旋轉的通知,當它收到一個,它切換視圖窗口,有點像這樣:自動旋轉視圖和UIDevice接口通知

- (void) orientationChanged: (NSNotification*) notice 
{ 
    UIDeviceOrientation newIO = [[UIDevice currentDevice] orientation]; 
    if (!UIDeviceOrientationIsValidInterfaceOrientation(newIO)) 
     return; 
    UIViewController *newCtrl = /* something based on newIO */; 
    [currentController.view removeFromSuperview]; // remove the old view 
    [window addSubview newCtrl.view]; 
    [self setCurrentController:newCtrl]; 
} 

的問題是,新視圖不會自動旋轉。我在控制器類自動旋轉回調看起來是這樣的:

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) io 
{ 
    NSString *modes[] = {@"unknown", @"portrait", @"portrait down", 
     @"landscape left", @"landscape right"}; 
    NSLog(@"shouldAutorotateToInterfaceOrientation: %i (%@)", io, modes[io]); 
    return YES; 
} 

但不管我怎麼旋轉裝置,我在日誌中發現以下幾點:

shouldAutorotateToInterfaceOrientation: 1 (portrait) 
shouldAutorotateToInterfaceOrientation: 1 (portrait) 

...和willRotateToInterfaceOrientation:duration:不根本不需要打電話。怎麼辦?方位改變正在成爲iPhone SDK的我最不喜歡的......(我不能檢查代碼在設備上呢,難道是在模擬器中的錯誤?)


PS。訂閱代碼如下所示:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(orientationChanged:) 
    name:UIDeviceOrientationDidChangeNotification 
    object:nil]; 

回答

0

的問題消失了,當我重新發布通知交換意見後:

[[NSNotificationCenter defaultCenter] 
    postNotificationName:UIDeviceOrientationDidChangeNotification 
    object:[UIDevice currentDevice]]; 

但是男孩,吸住。我仍然歡迎更好的解決方案。