0

一個小的變化多次,我使用UIDeviceOrientationDidChangeNotification調用的加速度

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

進行修改,在我的appdelegate一些看法。

但是,這被稱爲加速度計的最微小的變化。任何人都可以提出任何解決方法,以便它只在設備完全旋轉時才被調用。 謝謝

回答

1

在發佈通知之前,您可以編寫一些代碼來檢查設備的寬度= 480和高度= 320(這是設備旋轉90度的時間)嗎?

因此,像:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

... 

if(width == 480 && height == 320) 
{ 
    [[NSNotificationCenter defaultCenter] postNotification . . . ]; 
} 
+0

謝謝臧。將研究它。現在不在我的Mac上。 –

+0

不知道這將如何工作,因爲它只會發佈兩次。此檢查應位於通知的選擇器中。 – Bot

0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    //your code here 
} 

在您的視圖控制器中重寫此方法。它會在設備旋轉到新的方向時被調用

+0

我已經在我的問題,明確指出我在我的appdelegate使用它。不幸的是,這不起作用,因爲它不是一個UIViewController –

+0

你試圖做什麼樣的視圖更改?沒有UIViews沒有UIViewControllers這樣的事情。 –

+0

此代碼僅在視圖控制器內部起作用。不在appdelegate; –