2012-04-15 15 views
6

UIImagePickerControllerの表示可能なフレームサイズを変更することはできますか?私はカメラのビューを表示したいが画面全体には表示したくないが、100x100バウンディングボックスで言う。ここでUIImagePickerControllerのフレームサイズを設定する

は私のviewDidAppearです:

- (void) viewDidAppear:(BOOL)animated { 

UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
picker.showsCameraControls = NO; 
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront; 
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y); 

[self presentModalViewController:picker animated:YES]; 

[super viewDidAppear:YES]; 
} 

私はどこでも...それを使って人をdoesntのことを行うための方法を見つけることができませんでしたか?

+0

あなたはURの質問を解決しましたか? –

答えて

12

私は私の最後のポストからのコードを試し、最終的なスケール変換をコメントアウトしてフルサイズになり((1)と私は、私の画面の真ん中に浮かぶ美しい小型カメラimagePickerになってしまいました!それは間違いなく動作しない正確なコードは、私は、ズーム/フェードインの移行を含め、使用、である -

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 

imagePickerController.delegate = self; 
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]; 
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto; 

UIView *controllerView = imagePickerController.view; 

controllerView.alpha = 0.0; 
controllerView.transform = CGAffineTransformMakeScale(0.5, 0.5); 

[[[[UIApplication sharedApplication] delegate] window] addSubview:controllerView]; 

[UIView animateWithDuration:0.3 
        delay:0.0 
       options:UIViewAnimationOptionCurveLinear 
      animations:^{ 
       controllerView.alpha = 1.0; 
      } 
      completion:nil 
]; 

[imagePickerController release]; 

私はあなたが、より多くのそれをカスタマイズするカメラビューのサイズ&場所を変えることができると確信して

+1

awsome job dude – coder1010

+1

あなたのコードはうまくいきます。しかし、オーバーレイ画面の下のマージンは上の余白よりも大きいので、画面の中央に正確に来るわけではありません。それに対する解決策はありますか? –

+0

アニメーションのcontrollerViewの最終位置を変更するだけです:ブロック – SomaMan

1

ImagePickerのビューを直接追加したことがありますが、最終的なサイズを変更したことはありませんでしたが、画面に「ズーム」してさまざまなサイズで表示することができます直接)ので、おそらくすべての関連ではない私のプロジェクトの一つ、から -

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 

imagePickerController.delegate = self; 
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]; 
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto; 

UIView *controllerView = imagePickerController.view; 

controllerView.alpha = 0.0; 
controllerView.transform = CGAffineTransformMakeScale(0.5, 0.5); 

[[[[UIApplication sharedApplication] delegate] window] addSubview:controllerView]; 

[UIView animateWithDuration:0.3 
         delay:0.0 
        options:UIViewAnimationOptionCurveLinear 
       animations:^{ 
        controllerView.transform = CGAffineTransformMakeScale(1.0, 1.0); 
        controllerView.alpha = 1.0; 
       } 
       completion:nil 
]; 

[imagePickerController release]; 

あなたはこれですべての結果を得るかどうかを確認するために興味があります。

+0

nop、うまくいきませんでした...すごく簡単なことがどこにも見つからないことに驚いています。 – TommyG

3

私の場合のように、UIImagePickerControllerの上にオーバーレイを表示したい場合オーバレイのいくつかのUIコンポーネント(トップバーやボトムバーなど)の間にコントローラーの「ライブカメラフィード」(ビュー)を合わせるには、次のコードを使用します。これは、メインアプリケーションウィンドウのサブビューとしてではなく、現在のコントローラのサブビューとしてUIImagePickerControllerのビューを表示することの主な違いを、上記のSomaManの回答(感謝)に基づいています。 ()のviewDidLoadにこのコードを入れてください:

// Overlay view with custom camera controls and a top bar and a bottom bar 
self.overlay = [[CameraOverlayView alloc] initWithFrame:self.view.bounds]; 
[self setOverlayViewModel]; 

self.imagePicker = [[UIImagePickerController alloc] init]; 
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
self.imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto; 
self.imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff; 
self.imagePicker.showsCameraControls = NO; 
self.imagePicker.navigationBarHidden = YES; 
self.imagePicker.toolbarHidden = YES; 
self.imagePicker.delegate = self; 

UIView *imagePickerView = self.imagePicker.view; 

if ([[UIScreen mainScreen] bounds].size.height == 568.0f) { 
    // iPhone 5, 16:9 ratio, need to "zoom in" in order to fill the screen since there is extra space between top and bottom bars on a taller screen 
    self.imagePicker.cameraViewTransform = CGAffineTransformScale(self.imagePicker.cameraViewTransform, 1.5, 1.5); // change 1.5 to suit your needs 
} 
CGRect cameraViewFrame = CGRectMake(0, self.overlay.topBarHeight, 
            self.view.bounds.size.width, 
            self.view.bounds.size.height - self.overlay.topBarHeight - self.overlay.bottomBarHeight); 
imagePickerView.frame = cameraViewFrame; 

// keep this order so that the overlay view is on top of the "live camera feed" view 
[self.view addSubview:imagePickerView]; 
[self.view addSubview:self.overlay]; 

TIP:cameraViewTransformを行う場合、ユーザーが同じ画像で終わるしたい場合は、ピッカーがあなたのために捕獲することと同じで結果の写真に変換を適用することを確認してください彼らはあなたの変容したピッカーの見解を見ている:P

+0

@Alex - uiimageでのトランスフォームの設定方法? –

+0

@kshitijgodaraこんにちは、申し訳ありません、私は今これに気付きましたが、基本的には制限のためUIImagePickerControllerを使用していませんでした。 AVフレームワークを使用することは全く難しくありませんでした。私はブログ記事を書いて、他のものの一部としてそれをカバーしています:http://radioactiveukrainian.com/2014/01/06/testing-a-camera-app -in-ios-simulator / –

関連する問題