捕获映像不能正常工作



嗨,我是一个开发iOS应用程序的新手,请帮助我。我正面临着一个关于使用UIImagePicker捕获图像的问题。我在我们的应用程序中集成了嘻哈暴徒应用程序。

在该窗口中,我想显示一个UIButton,以便用户单击该UIButton应该捕获图像。当我点击按钮时,它抛出一个消息(其视图不在窗口层次结构中!)。

我认为这是由于这个聊天窗口。这是我的代码片段。

[[HMService sharedService] openChat:self withSetup:^(HMChatViewController * controller)
{
 controller.chatDelegate = self;
 controller.chatView.receivedMessageFont = [UIFont systemFontOfSize:20.0];
 controller.navigationBarHidden = YES;
 UIView * viewObjForVehicleDetails = [[UIView alloc]init];
 UIButton * btnForCaputrePhoto = [[UIButton alloc]init];
 [btnForCaputrePhoto addTarget:self action:@selector(CapturePhotoImage) forControlEvents:UIControlEventTouchUpInside];
  btnForCaputrePhoto.frame = CGRectMake(55, 90, 103, 85);
 [controller.chatView addSubview:viewObjForVehicleDetails];
 [viewObjForVehicleDetails addSubview:btnForCaputrePhoto];
 [[controller.chatView table] registerClass:[ChatTableViewCell class] forCellReuseIdentifier:@"ReuseChatTableViewCell"]; 
} 

 -(void)CapturePhotoImage
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:NO completion:nil];
}   

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}

提前感谢!

首先确保你在视图控制器中使用了以下委托

<UINavigationControllerDelegate, UIImagePickerControllerDelegate>

其次,使用这一行来显示ImagePicker:-

[self presentModalViewController:picker animated:YES];

替代方法:-

[self.view addSubview:imagePicker.cameraOverlayView]

修改方法声明如下

- (IBAction) CapturePhotoImage:(id)sender
{
    NSLog("Called");
}

方法调用"CapturePhotoImage"作为CapturePhotoImage:

 [btnForCaputrePhoto addTarget:self action:@selector(CapturePhotoImage:) forControlEvents:UIControlEventTouchUpInside];

最新更新