打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
【学习ios之路:UI系列】实现将图片保存到IOS自带的Photo Album中

 具体功能:

   在一个视图中有一个UIImageView,当长按UIImageView时,将UIImageView中的UIImage所代表的图片保存到PhotoAlbum中。


实现: 代码如下:self.imageView是定义的UIImageView视图属性

//长按效果- (void)longPanGesture {    UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self                                                               </span>action:@selector(longPanGesture:)];    [self.imageView addGestureRecognizer:longGesture];    longGesture.minimumPressDuration = 4;    [longGesture release];}
相应事件:longPanGesture方法实现

- (void)longPanGesture:(UILongPressGestureRecognizer *)longGesture {    if (longGesture.state == UIGestureRecognizerStateBegan) {        UIImageWriteToSavedPhotosAlbum([self.imageView image], nil, nil,nil);        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"存储照片成功"                              message:@"照片已存储于图片库中" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];        [alert show];        [alert release];    }}
UIImageWriteToSavedPhotosAlbum方法

 UIImageWriteToSavedPhotosAlbum是UIKit框架中的一个函数。这里说一下后面三个参数的含义:void UIImageWriteToSavedPhotosAlbum (   UIImage  *image,   id       completionTarget,   SEL      completionSelector,   void     *contextInfo);/**id是target对象*sel是selector.即target对象上的方法名*contextInfo是任意指针,会传递到selector定义的方法上。*一般是当完成后调用方法时使用,或者在完成时出错的处理。*/

原文:地址

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
iOS开发之详解剪贴板
iOS开发之异步加载图片
[iOS]设置显示毛玻璃效果(UIBlurEffect)
IOS GIF播放, 包含UITableViewCell中正常播放
iOS开发
iOS网络编程(三) 异步加载及缓存图片
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服