0

当用户长按图像时,我试图将图像从滚动视图保存到相册,操作表显示保存照片按钮,当点击保存按钮时,它没有将图像保存到相册

 - (void)viewDidLoad

{    self.view.backgroundColor = [UIColor blackColor];
UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
imageScrollView.pagingEnabled = YES;
NSInteger numberOfViews = 61;
for (int i = 0; i < numberOfViews; i++) {
    CGFloat xOrigin = i * self.view.frame.size.width;
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];

    [myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];

    myButton.frame = CGRectMake(xOrigin, 10, 60, 35);

    //[myButton addGestureRecognizer:tap];

    [myButton.layer setMasksToBounds:YES];

    [myButton.layer setCornerRadius:10.0f];

    myButton.layer.borderWidth = 2;

    myButton.layer.borderColor = [[UIColor whiteColor] CGColor];

    [myButton setTitle:@"Done" forState:UIControlStateNormal];

    myButton.backgroundColor = [UIColor clearColor];

    NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    _imageView.tag = 128;
    imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);


    UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc]
                                                       initWithTarget:self
                                                       action:@selector(handleLongPress:)];

    //imageScrollView.userInteractionEnabled = YES;
    [imageScrollView addGestureRecognizer:gestureRecognizer];
    gestureRecognizer.delegate = self;
    [gestureRecognizer release];

    [imageScrollView addSubview:imageView];
    [imageScrollView addSubview:myButton];

    //[imageView release];

}
imageScrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);

[self.view addSubview:imageScrollView];
[imageScrollView release];
 }



 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
    case 0:
    [_imageScrollView viewWithTag:128];
    UIImageWriteToSavedPhotosAlbum(_imageView.image, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);//When i add breakpoint at this statement in result it shows storage zero but alert view says success photo got saved in photo album

        break;

    default:
        break;
}
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
 {
if (error != NULL)
{

    alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                       message:@"Unable to save image to Photo Album."
                                      delegate:self cancelButtonTitle:@"Ok"
                             otherButtonTitles:nil];
     } else{
        alert = [[UIAlertView alloc] initWithTitle:@"Success"
                                           message:@"Image saved to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
    [alert show];
    [alert release];
   }
   }

请帮忙。

谢谢

4

1 回答 1

1

这可能是隐私设置的问题 - 人们一直在使用我的应用程序遇到此问题,并且没有报告错误消息。理论上,尝试保存照片应自动询问用户是否应允许该应用访问他们的照片,但在某些情况下,用户需要转到“设置”>“隐私”>“照片”并确保您的应用被允许。

于 2012-10-09T18:49:09.947 回答