2011-08-04 34 views
1

嗨,我有一個問題, 在我的AppDelegate我已經使用方法beginGeneratingDeviceOrientationNotifications開始通知我當設備開始旋轉。 它工作正常,如果我手持我的iPad,但當它保留在桌子上它不會按預期工作。 它會觸發UIDeviceOrientationUnknown通知。 此通知在UI啓動後不在啓動畫面上開始。設備在桌上時,UIDeviceOrientationDidChangeNotification不起作用?

下面是我的代碼:

if([[[PulseUIFactory Factory] GetUICreator] IsIPad]) 
    { 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
    } 
    current device stars giving proper values. 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

那麼一些在那裏我啓動我的UI作爲

[self Launch_UI]; 

但通知開始響應後[self Launch_UI];呼叫即使通知其調用之前註冊...

請任何幫助是可觀的!

回答

0

將設備放在桌子上時,[[UIDevice currentDevice] orientation]將返回UIDeviceOrientationFaceUp。然後,如果您的設備仍然面朝上坐在桌子上,那麼在桌子上旋轉它無關緊要,當前的設備方向仍然是UIDeviceOrientationFaceUp

如果設備在確定方向時遇到問題,您可能會得到UIDeviceOrientationUnknown。請參閱this教程,瞭解如何使用UIDeviceOrientationDidChangeNotification處理設備旋轉。

關於僅在加載用戶界面後觸發的通知,UIDeviceOrientationDidChangeNotification只會在設備旋轉時觸發。因此,如果您在用戶界面加載之前不旋轉設備,則不會收到通知。如果這不是問題的原因,那麼我必須看到更多的代碼才能更好地瞭解發生了什麼。

相關問題