UIImagePickerController takePicture方法

时间:2011-04-13 19:45:32

标签: iphone ios4 uiimagepickercontroller

目标:在其他GUI运行时以静音模式拍照。

操作系统:IOS 4.3

我正在进行测试,我想在执行ViewDidLoad时以静默模式拍摄一张图像: 我不想要任何相机gui如此永远......让我知道你的想法......

观察UIImagePickerController我看到我可以分配一些属性并执行takePicture方法..底线是当尝试执行它时没有发生任何事情,我看到几个KB ..它告诉你必须等待..所以我确实放了睡觉(10),但没有帮助。

也许我在某个地方错过了委托,而我读代表不是必须的.​​. 想法?

以下是代码:

标题文件:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface VisionViewController : UIViewController
{

    UIImagePickerController *controller;

}

-(void)settingControllerAndTakingPicture;


@end

和实施文件

//在加载视图后,通常从nib实现viewDidLoad以进行其他设置。 - (void)viewDidLoad {     [super viewDidLoad];

//Taking an Image

[self settingControllerAndTakingPicture ];

}

-(void)settingControllerAndTakingPicture

{
    controller = [[UIImagePickerController alloc] init];
    //Setting the control source type as the Camera device.
    controller.sourceType = UIImagePickerControllerSourceTypeCamera;

    //Camera display is off, the player will not see it during games.
    controller.showsCameraControls = NO;

    //Picking only the front camera.
    controller.cameraDevice = UIImagePickerControllerCameraDeviceFront;

    //Turning the camera flash off.
    controller.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;


    //Setting the controller view as self view
    controller.view = self.view;   

    //Taking a picture         
    [controller takePicture]; 


}

我再次对静音模式感兴趣。

1 个答案:

答案 0 :(得分:0)

您尚未将UIImagePickerController添加到视图层次结构中,直到您执行此操作时才会实例化。你需要presentModalViewController或类似的。

此外,我不认为更改controller.view会像你希望的那样工作,我想你可能不得不使用:

controller.showsCameraControls = NO;
controller.cameraOverlayView = self.view;

但这只是猜测。