2011-12-16 8 views

答えて

7

これは簡単な方法で行うことはできません(魔法の機能を有効または無効にするだけです)。単純な要件の場合は、cameraOverlayViewshowsCameraControlsを使用して実装を行うことができます。

あなたが写真/ビデオモードを切り替えたい場合、私はあなたがこのデモを確認することができると思います:http://developer.apple.com/library/ios/#samplecode/AVCam/Introduction/Intro.html

+0

ああ[OK]をクリックします。ありがとう!! – MBU

14

これは、次の行を介して行うことができます:ここでは

- (void) navigationController: (UINavigationController *) navigationController willShowViewController: (UIViewController *) viewController animated: (BOOL) animated { 
    if (imagePickerController.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) { 
     UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(showCamera:)]; 
     viewController.navigationItem.rightBarButtonItems = [NSArray arrayWithObject:button]; 
    } else { 
     UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithTitle:@"Library" style:UIBarButtonItemStylePlain target:self action:@selector(showLibrary:)]; 
     viewController.navigationItem.leftBarButtonItems = [NSArray arrayWithObject:button]; 
     viewController.navigationItem.title = @"Take Photo"; 
     viewController.navigationController.navigationBarHidden = NO; // important 
    } 
} 

- (void) showCamera: (id) sender { 
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
} 

- (void) showLibrary: (id) sender { 
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
} 
+2

これはカメラコントロールを変更するのではなく、代わりにナビゲーションバーをカメラウィンドウの上部に追加します。それはあなたが望むものかもしれないし、そうでないかもしれないが、私はOPが頭に入れていたものだとは思わない。 – DaGaMs

+2

すばらしい解決策。カメラのソースが実際に利用可能かどうかを忘れないでください。何かが好きです: if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ self.picker.sourceType = UIImagePickerControllerSourceTypeCamera; } – EsbenB

3

は、例えばアプリですと、非常にシンプルなライブラリで、Facebookのように写真を撮るか、ライブラリから選択することができます。 https://github.com/fulldecent/FDTake

1

私はAppleのPhotoPickerサンプルアプリケーションを修正しました。私はすべてのカメラコントロールを削除し、自分のボタンを追加しました。クリックすると、UIImagePickerControllerSourceTypeがUIImagePickerControllerSourceTypePhotoLibraryに設定されます。

画像を選んだ後、写真ライブラリの「却下」(技術的には間違った単語かもしれません)でした。ソースタイプをUIImagePickerControllerSourceTypeCameraに設定し直しました。これにより、カメラオーバーレイビューが表示されます。

ViewController.h 

#import <UIKit/UIKit.h> 
#import <CoreGraphics/CoreGraphics.h> 
#import <ImageIO/ImageIO.h> 


@interface ViewController : UIViewController <UIImagePickerControllerDelegate> { 

// 

} 

@property (nonatomic, strong) UIImagePickerController *imagePicker; 
- (IBAction)uploadNewPhotoTapped:(id)sender; 
@end 


ViewController.m 

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

//Other code 

- (IBAction)uploadNewPhotoTapped:(id)sender { 

    UIImagePickerController *imagePickController=[[UIImagePickerController alloc]init]; 
    //You can use isSourceTypeAvailable to check 

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
    { 
     imagePickController.sourceType=UIImagePickerControllerSourceTypeCamera; 
     imagePickController.showsCameraControls=YES; 
     // self.usingPopover = NO; 
    } 
    else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {//Check PhotoLibrary available or not 
     imagePickController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary; 
     imagePickController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    } 
    else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) //Check front Camera available or not 
     imagePickController.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
    //else //!!!!!!!!!!!exception 

    imagePickController.delegate=self; 
    imagePickController.allowsEditing=NO; 

    [self presentModalViewController:imagePickController animated:YES]; 
} 


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 

    UIImage *originalImage=[info objectForKey:UIImagePickerControllerOriginalImage]; 

    //Do whatever with your image 
    NSData *data = UIImageJPEGRepresentation (
              originalImage, 
              1.0 
             ); 

    [self dismissModalViewControllerAnimated:YES]; 
} 

    // Other code 
    @end 
+0

ここでゾンビを起こして申し訳ありませんが、コードがまだ残っていれば、本当に興味があります。 – bdv

+0

こんにちはbdv。私は実際に自分のコードを掘り出し、私の元の答えに投稿しました。私はこのアプリを2年間でやっていないので、私がどのようにしたのか正確に覚えていないが、私はAppleのオリジナルのPhotoPicker Appを使い始めた。 https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html – ganime

1

@epsilontikコードのSwift2バージョン:

//mediaPicker is your UIImagePickerController 
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) { 
    if(mediaPicker.sourceType == UIImagePickerControllerSourceType.PhotoLibrary){ 
     let button = UIBarButtonItem(title: "Take picture", style: UIBarButtonItemStyle.Plain, target: self, action: "showCamera") 
     viewController.navigationItem.rightBarButtonItem = button 
    }else{ 
     let button = UIBarButtonItem(title: "Choose picture", style: UIBarButtonItemStyle.Plain, target: self, action: "choosePicture") 
     viewController.navigationItem.rightBarButtonItem = button 
     viewController.navigationController?.navigationBarHidden = false 
     viewController.navigationController?.navigationBar.translucent = true 
    } 
} 

func showCamera(){ 
    mediaPicker.sourceType = UIImagePickerControllerSourceType.Camera 
} 

func choosePicture(){ 
    mediaPicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary 
} 
関連する問題