美文网首页
swift 长按保存图片

swift 长按保存图片

作者: yuyangkk | 来源:发表于2016-08-23 18:53 被阅读942次

1.添加手势

//添加长按手势
func addLongPressGestureRecognizer() {
    let longPress = UILongPressGestureRecognizer(target: self, action: #selector(self.longPressClick))
    self.qrcodeImageView.userInteractionEnabled = true
    self.qrcodeImageView.addGestureRecognizer(longPress)
}

2.长按手势事件

//长按手势事件
func longPressClick() {
    let alert = UIAlertController(title: "请选择", message: nil, preferredStyle: .ActionSheet)
    let action = UIAlertAction(title: "保存到相册", style: .Default) { [weak self](_) in
    //按着command键,同时点击UIImageWriteToSavedPhotosAlbum方法可以看到
    UIImageWriteToSavedPhotosAlbum(self!.qrcodeImageView.image!, self!, #selector(self!.image(_:didFinishSavingWithError:contextInfo:)), nil)
    let cancel = UIAlertAction(title: "取消", style: .Cancel, handler: nil)
    alert.addAction(action)
    alert.addAction(cancel)
    self.presentViewController(alert, animated: true, completion: nil)
}

Adds a photo to the saved photos album. The optional completionSelector should have the form:
-(void)image:(UIImage *)image didFinishSavingWithError:(NSError*)error contextInfo:(void *)contextInfo;

3.实现上述方法,保存图片

//保存二维码
func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
    if error == nil {
        let ac = UIAlertController(title: "保存成功", message: "请打开微信识别二维码关注", preferredStyle: .Alert)
        ac.addAction(UIAlertAction(title: "好的", style: .Default, handler: nil))
        presentViewController(ac, animated: true, completion: nil)
    } else {
        let ac = UIAlertController(title: "保存失败", message: error?.localizedDescription, preferredStyle: .Alert)
        ac.addAction(UIAlertAction(title: "好的", style: .Default, handler: nil))
        presentViewController(ac, animated: true, completion: nil)
    }
}

相关文章

  • swift 长按保存图片

    1.添加手势 2.长按手势事件 Adds a photo to the saved photos album. ...

  • 朋友圈封面 | 背景图 1.0

    ✎ 收图啦✦ 长按图片即可保存~ 长按图片即可保存图片~ 长按图片即可保存~ - The End- 图文 | 网络...

  • iPhone壁纸:6.20苹果高清壁纸

    长按保存 点击放大 iPhone手机壁纸(苹果(安卓)壁纸)保存方法:点击图片-长按图片-保存图片,保存完毕返回...

  • iPhone壁纸:文字锁屏壁纸

    长按保存 点击放大 iPhone手机壁纸(苹果(安卓)壁纸)保存方法:点击图片-长按图片-保存图片,保存完毕返回...

  • 壁纸:08-18今日高清唯美壁纸

    长按保存 点击放大 iPhone手机壁纸(苹果(安卓)壁纸)保存方法:点击图片-长按图片-保存图片,保存完毕返回...

  • iPhone壁纸:无水印壁纸

    长按保存 点击放大 iPhone手机壁纸(苹果(安卓)壁纸)保存方法:点击图片-长按图片-保存图片,保存完毕返回...

  • iPhone壁纸:7.5苹果高清壁纸

    长按保存 点击放大 iPhone手机壁纸(苹果(安卓)壁纸)保存方法:点击图片-长按图片-保存图片,保存完毕返回...

  • iPhone壁纸 : 抖音动漫原图

    长按保存 点击放大 iPhone手机壁纸(苹果(安卓)壁纸)保存方法:点击图片-长按图片-保存图片,保存完毕返回...

  • iPhone壁纸 : 高清壁纸原图

    长按保存 点击放大 iPhone手机壁纸(苹果(安卓)壁纸)保存方法:点击图片-长按图片-保存图片,保存完毕返回...

  • iPhone壁纸:全面屏壁纸

    长按保存 点击放大 iPhone手机壁纸(苹果(安卓)壁纸)保存方法:点击图片-长按图片-保存图片,保存完毕返回...

网友评论

      本文标题:swift 长按保存图片

      本文链接:https://www.haomeiwen.com/subject/vxdnsttx.html