objective-c - 删除我拍摄的照片

  显示原文与译文双语对照的内容
0 0

我正在试图做一个照片,保存照片库,选择一个现有的,并删除照片。 除了删除部分以外,我都做了。 你能帮我?


#pragma mark - Event

- (void)TakePhoto {

 UIImagePickerController * picker = [[UIImagePickerController alloc] init];

 picker.delegate = self;

 picker.sourceType = UIImagePickerControllerSourceTypeCamera;

 picker.allowsEditing = YES;

 [self presentViewController: picker animated: YES completion:NULL];

 self.newMedia = YES;
}

-(void)ChooseExisting {

 UIImagePickerController * picker = [[UIImagePickerController alloc] init];
 picker.delegate = self;
 picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
 picker.allowsEditing = YES;

 [self presentViewController: picker animated: YES completion:NULL];
 self.newMedia = NO;
}



#pragma mark - UIImagePickerControllerDelaegate

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

 NSString *mediaType = info[UIImagePickerControllerMediaType];

 [self dismissViewControllerAnimated:YES completion:NULL];

 UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

 self.imageView.image = image;

 if(self.newMedia) {
 UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:finishedSavingWithError:contextInfo:),nil);

 }
}

 -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

 [self dismissViewControllerAnimated:YES completion:nil];
 }

#pragma mark - Action Sheet

 - (void)showActionSheet:(id) sender {
 NSString *actionSheetTitle = @"Action Sheet Demo";
 NSString *destructiveTitle = @"Delete";
 NSString *other1 = @"Take Photo";
 NSString *other2 = @"Chose From Existing";
 NSString *cancelTitle = @"Cancel";

 UIActionSheet *actionSheet = [[UIActionSheet alloc]
 initWithTitle:actionSheetTitle
 delegate:self
 cancelButtonTitle:cancelTitle
 destructiveButtonTitle:destructiveTitle
 otherButtonTitles:other1, other2, nil];
 [actionSheet showInView:self.view];

 }


 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
 NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
 if ([buttonTitle isEqualToString:@"Delete"]) {
 NSLog(@"Destructive pressed --> Delete Something");
 }
 if ([buttonTitle isEqualToString:@"Take Photo"]) {
 [self TakePhoto];
 }
 if ([buttonTitle isEqualToString:@"Chose From Existing"]) {
 [self ChooseExisting];
 }

 if ([buttonTitle isEqualToString:@"Cancel Button"]) {
 NSLog(@"Cancel pressed --> Cancel ActionSheet");
 }
 }

#pragma mark - Alert

 -(void)image:(UIImage *)image finishedSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
 {
 if (error) {
 UIAlertView *alert = [[UIAlertView alloc]
 initWithTitle: @"Save failed"
 message: @"Failed to save image"
 delegate: nil
 cancelButtonTitle:@"OK"
 otherButtonTitles:nil];
 [alert show];
 }
 }

#pragma mark - Life Cycle

 -(void)viewDidLoad {
 [super viewDidLoad];
 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 button.frame = CGRectMake(20.0f, 186.0f, 280.0f, 88.0f);
 [button setTitle:@"Show Action Sheet" forState:UIControlStateNormal];
 [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
 button.tintColor = [UIColor darkGrayColor];
 [button addTarget:self action:@selector(showActionSheet:) forControlEvents:UIControlEventTouchUpInside];
 [self.view addSubview:button];

 if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

 UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
 message:@"Device has no camera"
 delegate:nil
 cancelButtonTitle:@"OK"
 otherButtonTitles: nil];

 [myAlertView show];

 }



 }



@end

时间: 原作者:

0 0

在删除图像时看到这个堆栈溢出帖子,但是链接中的信息表明只有应用程序创建的图像可以被删除。

从用户库照片中删除照片

...