1
目前,我正在使用此代碼,打開相機&視頻查看捕獲圖像&視頻:動態反覆打開攝像機視圖
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate
{
[optionView removeFromSuperview];
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
if (videoModeFlag==TRUE)
{
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[self presentViewController:cameraUI animated:YES completion:nil];
videoModeFlag=FALSE;
}
else
{
photoclick.sourceType = UIImagePickerControllerSourceTypeCamera;
photoclick.delegate = self;
[self presentViewController:photoclick animated:YES completion:nil];
}
return YES;
}
它的正常工作。但是我想反覆打開相機視圖,並在點擊使用按鈕時,我想將圖像保存到目錄。這是我想要的:
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{
saveFlag =TRUE;
[self.view addSubview:typename];
image = [[info objectForKey:UIImagePickerControllerOriginalImage] copy];
mediaType = [[info objectForKey: UIImagePickerControllerMediaType] copy];
movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] copy];
[self dismissViewControllerAnimated:YES completion:nil];
timer = [NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector: @selector(targetMethod)
userInfo:nil
repeats:YES];
- (void)targetMethod
{
a++;
[self startCameraControllerFromViewController: self
usingDelegate: self];
if (a==5)
{
[timer invalidate];
}
}
但無法成功地反覆打開相機。這裏是一個錯誤,我得到:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <ViewController: 0x49bab0>.'
,當我不使用定時器,那麼這是我在做什麼:
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{
saveFlag =TRUE;
//[self.view addSubview:typename];
image = [[info objectForKey:UIImagePickerControllerOriginalImage] copy];
mediaType = [[info objectForKey: UIImagePickerControllerMediaType] copy];
movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] copy];
[self dismissViewControllerAnimated:YES completion:nil];
NSMutableArray *sd=[[NSMutableArray alloc]init];
sd = [[getPickerData componentsSeparatedByString: @"\n--- end of page ---\n"] mutableCopy];
NSLog(@"sd:%@",sd);
for (int i=0; i<=[sd count]; i++)
{
[self startCameraControllerFromViewController: self
usingDelegate: self];
}
}
我停留在這一點上。我該如何解決這個問題?提前Thanx。
我正在嘗試使用Self方法來調用捕獲方法,但問題是相同的...... – Vishal
您能否更新修改後的代碼? –
我更新我的問題... – Vishal