我正在为iPhone 4 / 4S制作密码应用程序。当用户输入密码3次失败时,我想使用iPhone的前置摄像头拍摄用户的电影。这并不是什么新鲜事,appstore中的很多应用都做了类似的事情。拍下这个人的照片,得到他的GEO坐标等。
我面临的挑战是,当我尝试设置电影录制时,相机叠加会占据整个屏幕。我真正想要做的是让用户仍然看到登录屏幕和按钮,但秘密记录并制作用户的电影。有没有办法可以做到这一点?
这是我正在使用的代码。
在我的* .h文件中
@interface v1InstantController : UIViewController <UIImagePickerControllerDelegate>
{
UIImagePickerController *picpicker;
}
@property (nonatomic, retain) UIImagePickerController *picpicker;
在我的* .m文件中
-(IBAction) makeMovieNow
{
picpicker = [[UIImagePickerController alloc] init];
picpicker.delegate = self;
picpicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picpicker.sourceType = UIImagePickerControllerSourceTypeCamera;
picpicker.showsCameraControls = NO;
picpicker.navigationBarHidden = YES;
picpicker.wantsFullScreenLayout = NO;
picpicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
picpicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
picpicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
picpicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picpicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
picpicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
//The problem is right here!
//picpicker.cameraViewTransform = CGAffineTransformScale(picpicker.cameraViewTransform, 0.01, 0.01);
[self presentModalViewController:picpicker animated:YES];
[picpicker startVideoCapture];
}
问题就在这里“presentModalViewController:picpicker”。当我使用它时,它会启动带有Iris飞溅等的相机屏幕,它会显示整个屏幕上正在录制的内容。即使我使用cameraViewTransform,它仍然会禁用页面上的任何内容并将此相机覆盖放在页面中间。 (有一个非常小的相机覆盖)我不希望用户知道我正在录制,并希望他认为它像往常一样。即让他继续尝试在页面上输入密码失败。
答案 0 :(得分:5)
UIImagePickerController提供了一种从用户那里轻松获取照片/视频的方法,因此用户始终可以看到它。
由于您似乎需要更多控制权,因此您可以查看AVFoundation。 Apple Documentation应该提供一个很好的起点。
答案 1 :(得分:0)
以下是对未来感兴趣的人的答案。评价吧!
确保包含coreVideo和CoreMedia框架
你的* .h文件中的
@interface v1InstantController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
AVCaptureSession *session;
NSString *videoPath2;
}
@property (nonatomic, retain) AVCaptureSession *session;
@property (nonatomic, retain) NSString *videoPath2;
你的* .m文件中的
@synthesize session;
@synthesize videoPath2;
-(IBAction) makeMovieNow
{
NSLog(@"makeMovieNow ..");
//record movie
session = [[AVCaptureSession alloc] init];
[session beginConfiguration];
session.sessionPreset = AVCaptureSessionPresetHigh;
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
NSError *error = nil;
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
device = [self frontFacingCameraIfAvailable];
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!videoInput)
{
// Handle the error appropriately.
NSLog(@"ERROR: trying to open camera: %@", error);
}
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeAudio];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error ];
AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *movieFileName = [NSString stringWithFormat: @"Secret.mov"];
NSString *fullPathToFile2 = [documentsDirectoryPath stringByAppendingPathComponent:movieFileName];
NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:fullPathToFile2];
videoPath2=[outputURL path];
[session addInput:videoInput];
[session addInput:audioInput];
[session addOutput:movieFileOutput];
[session commitConfiguration];
//start recording
[session startRunning];
[movieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
}
-(IBAction) makeMovieStop
{
NSLog(@"makeMovieStop ...");
//stop recording
[session stopRunning];
//save video to photo-album
UISaveVideoAtPathToSavedPhotosAlbum(videoPath2, self, nil, nil);
}