首页 > 移动平台 > 详细

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

时间:2015-01-16 16:43:39      阅读:243      评论:0      收藏:0      [点我收藏+]

具体功能:

   在一个视图中有一个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定义的方法上。
*一般是当完成后调用方法时使用,或者在完成时出错的处理。
*/

原文:地址

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

原文:http://blog.csdn.net/zfx5130/article/details/42776523

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!