2013-04-08 13 views
7

こんにちは私は、向きがランドスケープにシフトされたときにカメラアプリで見ることができる同じ回転を再現しようとしています。残念ながら私は運がなかった。 UIImagePickerControllerを使ってカスタムcameraOverlayViewを設定する必要があります。言い換えれば、この肖像画からカメラアプリの回転をランドスケープに複製するIOS iPhone

(BがUIButtonsある)

|-----------| 
|   | 
|   | 
|   | 
|   | 
|   |  
|   | 
| B B B | 
|-----------| 
この風景に

|----------------| 
|    B | 
|    | 
|    B | 
|    | 
|    B | 
|----------------| 

私は、元の肖像底に固執し、その中心に回転させるためにボタンをしたいと思います。ストーリーボードを使用していて、自動レイアウトが有効になっています。どんな助けでも大歓迎です。

+0

はもう少し前に同じ質問をしました - http://stackoverflow.com/questions/15377120/uiimagepickercontroller-record-video-with-landscape-orientation残念ながらまだ素敵な答えはありません。 –

+0

さて、私はxcodeのAutolayout Constraintsを使いこなしましたが、オリジナルの縦長のボトムではなく、現在のオリエンテーションのボトムに要素を固定することは明らかです。私の次の試みは、実行時に ' - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration'というコンストレイントを設定しようとしています。 – pechar

答えて

15

OK、これを整理することができました。注目すべき点は、UIImagePickerControllerクラスはApple documentationに従ってのみポートレートモードをサポートしていることです。

ここで回転をキャプチャするにはwillRotateToInterfaceOrientationは役に立たないので、通知を使用する必要があります。また、実行時に自動レイアウト制約を設定する方法はありません。

あなたが有効になって回転通知に必要AppDelegate didFinishLaunchingWithOptions

:cameraOverlayView UIViewControllerviewDidLoad方法で

// 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.なぜこれが起こっているのかわかりませんが、それはカメラの表示と関係があります。

上記が役に立ちますようお願いいたします。

+0

ありがとうございます。これは本当に私を助けました。 – Zigglzworth

+0

助けがよかったとうれしい! – pechar

関連する問題