iOS开发-OC之图片保存到相册
来源:互联网 发布:爱奇艺网络剧 编辑:程序博客网 时间:2024/05/22 12:32
- #import "ViewController.h"
- @interface ViewController ()
- @property (nonatomic , strong)UIAlertView *myAlertView;
- @property (nonatomic , strong)UIAlertView *myAlertView2;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
- imageView.image = [UIImage imageNamed:@"User_load.jpg"];
- imageView.tag = 10001;
- imageView.userInteractionEnabled = YES;
- [self.view addSubview:imageView];
- //长按
- UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPassAction:)];
- [imageView addGestureRecognizer:longPress];
- //判定为长按手势 需要的时间
- longPress.minimumPressDuration = 1;
- //判定时间,允许用户移动的距离
- longPress.allowableMovement = 100;
- }
- //长按手势
- - (void)longPassAction:(UILongPressGestureRecognizer *)longPress{
- NSLog(@"11111");
- //长按手势
- if (longPress.state == UIGestureRecognizerStateBegan) {
- self.myAlertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您要保存当前图片到相册中吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"保存", nil nil];
- [self.myAlertView show];
- }
- }
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (buttonIndex == 1) {
- // 保存照片(获取到点击的 image)
- // NSInteger i = self.scroll.contentOffset.x / self.scroll.bounds.size.width;
- UIImageView *myImageView = (UIImageView *)[self.view viewWithTag:10001];
- UIImageWriteToSavedPhotosAlbum(myImageView.image, self, @selector(image:didFinshSavingWithError:contextInfo:), nil);
- }
- }
- // 保存图片错误提示方法
- - (void)image:(UIImage *)image didFinshSavingWithError:(NSError *)error contextInfo:(voidvoid *)contextInfo
- {
- NSString *mes = nil;
- if (error != nil) {
- mes = @"保存图片失败";
- } else {
- mes = @"保存图片成功";
- }
- self.myAlertView2 = [[UIAlertView alloc] initWithTitle:@"提示" message:mes delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
- [self.myAlertView2 show];
- [NSTimer scheduledTimerWithTimeInterval:0.8f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];
- }
- - (void)performDismiss:(NSTimer *)timer
- {
- [self.myAlertView2 dismissWithClickedButtonIndex:0 animated:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
0 0
- iOS开发-OC之图片保存到相册
- iOS开发之保存图片到手机相册
- iOS开发之保存图片到手机相册
- iOS开发之保存图片到手机相册
- iOS保存图片到相册
- iOS保存图片到相册
- ios 图片保存到 相册
- iOS 保存图片到相册
- iOS 图片保存到相册
- iOS 保存图片到相册
- iOS 保存图片到相册
- iOS 保存图片到相册
- iOS开发 - 保存图片到相册和保存屏幕截图到相册
- ios开发 把视频文件和图片保存到相册
- IOS开发——保存图片到相册
- 关于iOS开发中长按保存图片到相册
- iOS开发 长按图片保存到相册
- iOS之保存图片到手机相册中
- 如何使用tspan元素给SVG文本添加样式、定位
- weblogic 启动报错
- .9.png一些总结
- 【C++】找数组中唯一出现两次的数
- 一些Qt技巧
- iOS开发-OC之图片保存到相册
- JAVA设计模式之单例模式
- 小巧而功能强大的工具vncconfig
- 小巧免费的图片文字识别OCR软件 支持简体识别和竖排繁体中文
- 如何用AngularJS使用ECharts画图
- Masonry使用中equalTo和mas_equalTo的区别
- 事务的 原子性、一致性、隔离性、持久性
- 性能测试场景设计杂谈
- 高并发联机事物处理