• iOS,长按图片保存实现方法,轻松搞定!


    1、添加手势识别:

     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imgTapCliclk:)];

      UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(imglongTapClick:)];

      2、imaglongTapClick:

    -(void)imglongTapClick:(UILongPressGestureRecognizer *)gesture

    {

        if(gesture.state == UIGestureRecognizerStateBegan)

        {

            UIActionSheet *actionSheet = [[UIActionSheet alloc]

                                          initWithTitle:@"保存图片"

                                          delegate:self

                                          cancelButtonTitle:@"取消"

                                          destructiveButtonTitle:nil

                                          otherButtonTitles:@"保存图片到手机",nil];

            actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;

            [actionSheet showInView:self];

        

            UIImageView *img = (UIImageView *)[gesture view];

            _sentImg = img;

        }

    }

    - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex

    {

        if (buttonIndex == 0) {

            UIImageWriteToSavedPhotosAlbum(_sentImg.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);

        }

    }

     

     

    #pragma mark --- UIActionSheetDelegate---

    - (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo

    {

        NSString *message = @"呵呵";

        if (!error) {

            message = @"成功保存到相册";

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];

            [alert show];

            

        }else

        {

            message = [error description];

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];

            [alert show];

        }

    }

     

     

     

     

     

     

     

     

  • 相关阅读:
    defineProperty的使用
    js题库全集
    如何将多个文件夹中的文件合并到一个文件夹中
    CYQ.Data V5 MDataTable 专属篇介绍
    读取和写入配置文件内容的方法
    面对代码中过多的if...else的解决方法
    SQL语句--删除掉重复项只保留一条
    获取当前时间
    Stopwatch 类用于计算程序运行时间
    正则表达式手册
  • 原文地址:https://www.cnblogs.com/JASON-SONG/p/4930351.html
Copyright © 2020-2023  润新知