OK、これを整理することができました。注目すべき点は、UIImagePickerControllerクラスはApple documentationに従ってのみポートレートモードをサポートしていることです。
ここで回転をキャプチャするにはwillRotateToInterfaceOrientation
は役に立たないので、通知を使用する必要があります。また、実行時に自動レイアウト制約を設定する方法はありません。
あなたが有効になって回転通知に必要AppDelegate
didFinishLaunchingWithOptions
で
:cameraOverlayView UIViewController
のviewDidLoad
方法で
// send notification on rotation
[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];
は、次の行を追加します。
//add observer for the rotation notification
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
は最後にcameraOverlay UIViewController
に
orientationChanged:
メソッドを追加
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
double rotation = 0;
switch (orientation) {
case UIDeviceOrientationPortrait:
rotation = 0;
break;
case UIDeviceOrientationPortraitUpsideDown:
rotation = M_PI;
break;
case UIDeviceOrientationLandscapeLeft:
rotation = M_PI_2;
break;
case UIDeviceOrientationLandscapeRight:
rotation = -M_PI_2;
break;
case UIDeviceOrientationFaceDown:
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationUnknown:
default:
return;
}
CGAffineTransform transform = CGAffineTransformMakeRotation(rotation);
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.btnCancel.transform = transform;
self.btnSnap.transform = transform;
}completion:nil];
}
上記のコードは、この例ではbtnCancelとbtnSnapを使用している2つのUIButtonに回転変換を適用しています。これにより、デバイスを回転させるときにカメラアプリの効果が得られます。 私はまだコンソールで警告を受けています<Error>: CGAffineTransformInvert: singular matrix.
なぜこれが起こっているのかわかりませんが、それはカメラの表示と関係があります。
上記が役に立ちますようお願いいたします。
はもう少し前に同じ質問をしました - http://stackoverflow.com/questions/15377120/uiimagepickercontroller-record-video-with-landscape-orientation残念ながらまだ素敵な答えはありません。 –
さて、私はxcodeのAutolayout Constraintsを使いこなしましたが、オリジナルの縦長のボトムではなく、現在のオリエンテーションのボトムに要素を固定することは明らかです。私の次の試みは、実行時に ' - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration'というコンストレイントを設定しようとしています。 – pechar