首页 > 代码库 > ios 中长按图片或者二维码,保存图片到手机的方法

ios 中长按图片或者二维码,保存图片到手机的方法

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000 } span.s1 { color: #6122ae } span.s2 { } span.s3 { color: #c42275 } span.s4 { color: #3e1e81 } span.s5 { color: #0435ff } span.s6 { color: #703daa }</style> <style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3e1e81 } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000; min-height: 21.0px } p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #539aa4 } p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1e9421 } p.p6 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #703daa } p.p7 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #6122ae } p.p8 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC"; color: #1e9421 } span.s1 { } span.s2 { color: #c42275 } span.s3 { color: #539aa4 } span.s4 { color: #6122ae } span.s5 { color: #3e1e81 } span.s6 { color: #703daa } span.s7 { color: #0435ff } span.s8 { color: #000000 } span.s9 { color: #294c50 } span.s10 { font: 18.0px Menlo; color: #000000 } span.s11 { font: 18.0px Menlo }</style>

 self.imageView = [[UIImageView alloc]init];

    self.imageView.frameCGRectMake(30, titleLabel.height+30, self.neirongView.width-60, 170);

    self.imageView.contentMode=UIViewContentModeScaleAspectFit;

    

    [self.imageView setImageWithURL:[NSURL URLWithString:_ImageUrl]];

    [self.neirongView addSubview:self.imageView];

    self.imageView.tag = 1234;

//    self.imageView.backgroundColor =Table_BGColor;

    self.imageView.userInteractionEnabled =YES;

    UILongPressGestureRecognizer*longpress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(imageClick)];

    //判定为长按手势 需要的时间

    longpress.minimumPressDuration = 1;

    [self.imageView addGestureRecognizer:longpress];

 

 

 

-(void)imageClick{

UIImageView *myImageView = (UIImageView *)[self viewWithTag:1234];

        UIImageWriteToSavedPhotosAlbum(myImageView.imageself@selector(image:didFinshSavingWithError:contextInfo:), nil);


}

 

 

 

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC"; color: #1e9421 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000 } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000; min-height: 21.0px } p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3e1e81 } span.s1 { font: 18.0px Menlo } span.s2 { } span.s3 { color: #c42275 } span.s4 { color: #6122ae } span.s5 { color: #c81b13 } span.s6 { font: 18.0px "PingFang SC"; color: #c81b13 } span.s7 { color: #294c50 } span.s8 { color: #000000 } span.s9 { color: #0435ff }</style>

// 保存图片错误提示方法

- (void)image:(UIImage *)image didFinshSavingWithError:(NSError *)error contextInfo:(void *)contextInfo

{

    

    

    NSString *mes = nil;

    if (error != nil) {

        mes = @"保存图片失败";

    } else {

        mes = @"保存图片成功";

    }

   

    [self makeToast:mes];

    [NSTimer scheduledTimerWithTimeInterval:0.8f target:self selector:@selector(fadeOut) userInfo:nil repeats:NO];

}

 

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3e1e81 } span.s1 { } span.s2 { color: #c42275 } span.s3 { color: #000000 } span.s4 { color: #6122ae } span.s5 { color: #0435ff } span.s6 { color: #703daa } span.s7 { color: #3e1e81 }</style>

- (void)fadeOut{

    [UIView animateWithDuration:.35 animations:^{

        self.alpha = 0.0;

    }completion:^(BOOL finished) {

        if (finished){

            [self removeFromSuperview];

        }

    }];

}

ios 中长按图片或者二维码,保存图片到手机的方法