我使用的代码允许应用程序只运行一次相机或照片库。我已经使用不同的索引在actionSheet上实现了这两个操作。使用相机或照片库拾取图像,但这是第一次。第二次如果用户尝试使用其中任何一个操作..应用程序在此特定点崩溃: -
self.imagePickerController.sourceType = sourceType;
可能是什么原因? 该方法包含的代码如下: -
- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType {
self.imagePickerController.sourceType = sourceType;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
// user wants to use the camera interface
self.imagePickerController.showsCameraControls = NO;
if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0)
{
// setup our custom overlay view for the camera
// ensure that our custom view's frame fits within the parent frame
CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0,
CGRectGetHeight(overlayViewFrame) -
self.view.frame.size.height - 10.0,
CGRectGetWidth(overlayViewFrame),
self.view.frame.size.height + 10.0);
self.view.frame = newFrame;
[self.imagePickerController.cameraOverlayView addSubview:self.view];
}
}
}
答案 0 :(得分:0)
您发送到设置方法的变量sourceType
在第二轮时会以某种方式损坏。
在您的程序逻辑中,请确保使用正确的参数调用setupImagePicker
。
答案 1 :(得分:0)
查看此代码
-(IBAction)TakePicture:(id)sender{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
if([UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront ]){
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceFront ;
}
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Camera is not available for this Device" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
self.takephoto.selected = NO;
return;
}
self.picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
self.picker.wantsFullScreenLayout = YES;
self.picker.allowsEditing=YES;
// Insert the overlay
if (!self.overlay) {
self.overlay = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
}
self.overlay.pickerReference = self.picker;
self.picker.cameraOverlayView = self.overlay.view;
self.picker.delegate = self;
[self presentModalViewController: self.picker animated:NO];
// [[UIApplication sharedApplication] endIgnoringInteractionEvents];
}