【问题标题】:Saving always first image from scrollview to photo album始终将第一张图像从滚动视图保存到相册
【发布时间】:2012-10-10 20:28:21
【问题描述】:

为什么当我一直选择第二张或任何其他图像时它只将滚动视图中的第一张图像保存到相册中,它只将滚动视图中的第一张图像保存到相册

- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer{
//CGPoint gesturePoint = [_gesture locationInView:_imageScrollView]; 
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Save Photo", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [actionSheet showInView:self.view];
    [actionSheet release];

}}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
    case 0:
         for (int i = 0; i<=61; i++) {
             NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
             UIImage *image = [UIImage imageNamed:imageName];
             UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
             //if     (CGRectContainsPoint(_myButton.frame,gesturePoint)){  
        UIImageWriteToSavedPhotosAlbum(imageView.image, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);

       break;

    default:
        break;
} }}

它应该总是保存选择的图像。

请帮忙。

谢谢

【问题讨论】:

    标签: iphone ios6


    【解决方案1】:

    您的代码有几个问题。

    1. 您正在创建UIImageView,但您并没有使用它,只是使用了图像。这个对象真的没有用。

    2. 你应该检查image0.pngimage1.pngimage2.png是否真的存在。一个简单的NSLog 语句将向您展示。如果他们是nil,那么他们没有被保存也就不足为奇了。

    3. 您的代码中没有任何地方引用该选择,您只需使用硬编码的 62 个图像数。您的 imageNamed 方法会将这些从应用程序包中拉出(如果存在)。

    【讨论】:

    • 有些人总是把每件事都告诉我两次有些人会说两次我认为你应该阅读我的答案你应该阅读我写的这个答案
    猜你喜欢
    • 2014-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    相关资源
    最近更新 更多