我需要知道方向何时从纵向切换到横向,反之亦然。如果我选择听,UIDeviceOrientationDidChangeNotification
我会面朝上、面朝下等,但只有在界面旋转时才需要运行代码。
我可以这样做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;
}
最好的方法是什么?