直接贴.m文件代码

#import "UIImageView+Scale.h"

static CGRect oldframe;

@implementation UIImageView (Scale)

//放大

-(void)showImageView:(UIImageView *)targetImgView {

UIImage *image = targetImgView.image;

UIWindow *window = [UIApplication sharedApplication].keyWindow;

UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

oldframe =[targetImgView convertRect:targetImgView.bounds toView:window];

bgView.backgroundColor = [UIColor lightGrayColor];

bgView.alpha = 0;

UIImageView *imageView = [[UIImageView alloc ] initWithFrame:oldframe];

imageView.image = image;

imageView.tag = 1001;

[bgView addSubview:imageView];

[window addSubview:bgView];

bgView.userInteractionEnabled = YES;

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

[bgView addGestureRecognizer:tap];

//如果图片还没有加载出来会卡在这里

if (image) {

[UIView animateWithDuration:0.3 animations:^{

imageView.frame = CGRectMake(0,  (SCREEN_HEIGHT - image.size.height * SCREEN_WIDTH / image.size.width)/2, SCREEN_WIDTH, image.size.height * SCREEN_WIDTH/image.size.width);

bgView.alpha = 1;

}];

}

UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(bgView.right - 80, imageView.bottom + 10, 80, 30)];

[btn setTitle:@"保存" forState:0];

[bgView addSubview:btn];

[btn addTarget:self action:@selector(saveImage:) forControlEvents:UIControlEventTouchUpInside];

}

//缩小隐藏

- (void)hideImage:(UITapGestureRecognizer *)tap {

UIView *backgroundView=tap.view;

UIImageView *imageView=(UIImageView*)[tap.view viewWithTag:1001];

[UIView animateWithDuration:0.5 animations:^{

imageView.frame = oldframe;

backgroundView.alpha=0;

} completion:^(BOOL finished) {

[backgroundView removeAllSubviews];

[backgroundView removeFromSuperview];

}];

}

//保存

- (void)saveImage:(UIButton *)sender {

UIImageView *imageView = (UIImageView *)[sender.superview viewWithTag:1001];

UIImage *image = imageView.image;

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

}

//保存回调

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

NSString *message;

if (!error) {

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

}else {

message = [error description];

}

NSLog(@"message is %@",message);

[MBProgressHUD showHUD:message];

}

@end

ios 点击放大图片,保存至手机相册的更多相关文章

  1. 微信小程序base64图片保存到手机相册

    问题:base64图片不能直接用wx.saveImageToPhotosAlbum保存到手机相册 解决: 先用fs.writeFile写入本地文件,再wx.saveImageToPhotosAlbum ...

  2. jquery插件jquery.LightBox.js之点击放大图片并左右点击切换图片(仿相册插件)

    该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 此插件旨在实现目前较为流行的点击放大图片并左右点击切换图片的效果,您可以根据自己的实 ...

  3. React Native之图片保存到本地相册(ios android)

    React Native之图片保存到本地相册(ios android) 一,需求分析 1,react native保存网络图片到相册,iOS端可以用RN自带的CameraRoll完美解决,但是andr ...

  4. IOS下拉放大图片

    代码地址如下:http://www.demodashi.com/demo/11623.html 一.实现效果图 现在越来越多的APP中存在下拉放大图片的效果,今天贡献一下我的实现这种方法的原理,和我遇 ...

  5. 小程序base64图片格式保存至手机相册

    // 保存图片至相册 saveImg() { //获取文件管理器对象 const fs = wx.getFileSystemManager() //文件保存路径 const Imgpath = wx. ...

  6. 小程序canvas生成海报保存至手机相册

    小程序canvas画图保存至手机相册 (1)可直接展示生成的海报 .因手机分辨率不同可能导致生成的海报会有细微差别,这里隐藏canvas海报,页面正常设置海报样式保存时保存隐藏的canvas海报 (2 ...

  7. 微信小程序点击按钮将图片保存到手机

    SaveCard: function(e) { let that = this; console.log('保存'); var imgSrc = e.currentTarget.dataset.img ...

  8. js限制图片大小、点击放大图片、点击在新开页面显示

    缩放图片到合适大小        function ResizeImages() {            var myimg, oldwidth, oldheight;            var ...

  9. flutter 长按图片保存到手机

    main.dart import 'dart:io'; import 'package:flutter/material.dart'; import 'package:http/http.dart' ...

随机推荐

  1. 【Zookeeper】源码分析之持久化--FileTxnLog

    一.前言 前一篇已经分析了序列化,这篇接着分析Zookeeper的持久化过程源码,持久化对于数据的存储至关重要,下面进行详细分析. 二.持久化总体框架 持久化的类主要在包org.apache.zook ...

  2. Js-Html 前端系列--checkbox

    今天搞全选按钮,设置Checkbox的时候,处于Checked状态但是不显示勾.最后得出解决方案: var c = boxcList.eq(i).attr("checked"); ...

  3. Linux虚拟机下安装配置MySQL

    一.      下载mysql5.7 http://mirrors.sohu.com/mysql/MySQL-5.7/ Linux下载: 输入命令:wget http://mirrors.sohu.c ...

  4. SQL注入(三)

    邮给我一个密码 我们意识到虽然不能添加一条新的记录在members表中,但我们可以通过修改一个存在的记录, 这也获得了我们的证明是可行的. 从先前的步骤中,我们知道bob@example.com在系统 ...

  5. crontab 定时的陷阱

    crontab  任务不执行,首先要查询一下cron任务的宿主和语法: (1). /etc/cron.d/cron_zengtai   这个文件必须是 root:root  否则cron_zengta ...

  6. MySQL对NULL值的处理

    mysql: 我们已经知道MySQL使用 SQL SELECT 命令及 WHERE 子句来读取数据表中的数据,但是当提供的查询条件字段为 NULL 时,该命令可能就无法正常工作. 为了处理这种情况,M ...

  7. 使用ab对站点进行压力测试

    测试指令: window下: E:\wamp\bin\apache\Apache2.2.21\bin> .\ab -V  //查看是否按照了ab:(V 大写) E:\wamp\bin\apach ...

  8. Canvas裁剪和Region、RegionIterator

    主要是看这边文章学习:http://blog.csdn.net/lonelyroamer/article/details/8349601 Region.op参数 DIFFERENCE(0), //最终 ...

  9. Oracle的闪回技术--闪回错误的DML操作

    提交DML操作后,该操作使用的还原段就可以被其它对象使用了,为了保证闪回操作时这些数据仍然被保存在还原段中,可能需要重新设置undo_retention参数,表示一个事务提交后,该事务的数据必须保存在 ...

  10. 可参考的gulp资源

    可参考的gulp资源 入门:https://segmentfault.com/a/1190000000435599 比较详细:https://markpop.github.io/2014/09/17/ ...