从照片库中的ImageScrollView保存图像

时间:2012-10-08 15:26:10

标签: iphone uiscrollview uiimageview ios6

当用户在imageview上长按时,如何在照片库中保存此滚动视图中的图像。

获取声明的黄色警告

  UIImageWriteToSavedPhotosAlbum(_imageScrollView, self, nil, nil);

如何解决此警告以在照片库中保存图像

- (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;
    NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);
    UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc]
                                               initWithTarget:self
                                               action:@selector(handleLongPress:)];
    gestureRecognizer.minimumPressDuration = 2.0;
     imageScrollView.userInteractionEnabled = YES;
     [imageScrollView addGestureRecognizer:gestureRecognizer];
    gestureRecognizer.delegate = self;
    [gestureRecognizer release];
    [imageScrollView addSubview:imageView];
    [imageScrollView addSubview:myButton];

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

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

- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer{

if (gestureRecognizer.state == UIGestureRecognizerStateEnded){
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Save Photo", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
    [actionSheet showInView:self.view];
    [actionSheet release];

}

}

    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
    case 0:
        UIImageWriteToSavedPhotosAlbum(_imageScrollView, self, nil, nil);

        break;

    default:
        break;
}
}

在此声明中以黄色显示警告

     UIImageWriteToSavedPhotosAlbum(_imageScrollView, self, nil, nil);

incompatible pointer types passing UIScrollView to parameter of type UIImage

谢谢

1 个答案:

答案 0 :(得分:0)

见 这个:saving image 和 这个:download and saving image

但是这个评分很高prev. answer