向きが縦から横に、またはその逆にいつ切り替わるかを知る必要があります。聞くことを選択した場合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;
}
最善のアプローチは何ですか?