1
我需要知道何時從縱向切換到橫向,反之亦然。 如果我選擇傾聽UIDeviceOrientationDidChangeNotification
我正面朝上,面朝下等,但只有在有界面旋轉時才需要運行代碼。IOS6我怎樣才能聽取界面方向。不是設備方向
我能做的http://the.ichibod.com/kiji/how-to-handle-device-rotation-for-uiviews-in-ios/
- (void)deviceOrientationDidChange:(NSNotification *)notification {
//Obtaining the current device orientation
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
//Ignoring specific orientations
if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown || orientation == UIDeviceOrientationUnknown || currentOrientation == orientation) {
return;
}
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(relayoutLayers) object:nil];
//Responding only to changes in landscape or portrait
currentOrientation = orientation;
}
什麼是最好的方法?
真的很好!但是我仍然需要保存最後的方向,以便比較並確保它是從縱向到橫向而不是從正面到景觀的旋轉? – Toydor
只需將先前的方向狀態存儲爲類var,那麼當您的視圖出現時,請保存它所在的方向。然後在deviceorientationdidchange上執行它。 – mashdup
所以蘋果不贊成willrotatetointerfaceorientation,他們沒有任何好的選擇。我的天! – Toydor