zoukankan      html  css  js  c++  java
  • 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];

        }

    }

     

     

     

     

     

     

     

     

  • 相关阅读:
    快排笔记C++
    security+redis+jwt 一个登陆注册查询的例子
    centeros 配置好环境虚拟机下载(java git mysql maven nginx Python redis nodejs tomcat )
    ZwQueryInformationProcess 反调试代码
    c++ 创建进程设置窗口标题模拟键盘鼠标例子
    求一个数二进制中包含多少个1
    憨批是我
    憨批是我
    问卷星实现自动填表刷问卷(问卷星分析post协议实现 安卓版)
    前端面试题 -- 综合
  • 原文地址:https://www.cnblogs.com/JASON-SONG/p/4930351.html
Copyright © 2011-2022 走看看