我的应用上有自定义相机。我在相机视图上添加了一个按钮,以便用户可以根据需要从相册中选择图像。一旦他们选择了图像,他们就会将其裁剪成正方形,然后到达编辑屏幕。我遇到的问题是,一旦用户裁剪图像并轻敲"完成",它就会回到相机而不是进入编辑屏幕。 这是我的代码:
- (void)viewDidLoad{
[super viewDidLoad];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
//isAlbum = NO;
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSData *data = [def objectForKey:@"imageData"];
if([NSStringFromClass([data class]) isEqualToString:@"NSData"]){
[self performSeague];
}
// [self.view sendSubviewToBack:self.cameraView];
// Do any additional setup after loading the view, typically from a nib.
[self setupAVCapture];
[self setLatestPicture];
[_AlbumView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[_AlbumView.layer setBorderWidth:2.0];
[overlayView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cameraOverlay.png"]]];
[self.view bringSubviewToFront:overlayView];
}
else{
[self performSeague];
}
[self performSeague]
转到UIImagePickerController(不同的控制器)。这是代表的代码
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *image = [info valueForKey:UIImagePickerControllerEditedImage];
NSData *data = [[NSData alloc]init];
data = UIImagePNGRepresentation(image);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:data forKey:@"imageData"];
[self performSegueWithIdentifier:@"pictureSelectedSeague" sender:self];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:NO completion:^{
[self performSegueWithIdentifier:@"cancelSeage" sender:self];
}];
}
此处如果用户取消,我会回到相机并且它可以正常工作但是当用户完成选择已编辑的图像时,它不会跟随[self performSegueWithIdentifier:@"pictureSelectedSeague" sender:self];
这行代码,而是取消选择器并返回到相机视图。
答案 0 :(得分:-1)
使用[picker dismissModalViewControllerAnimated:NO];
下面的代码解析didFinishPickingMediaWithInfo方法中的imagepicker模型视图