iOS常见功能demoIOS收藏

iOS保存图片本地,复制粘贴

2016-01-07  本文已影响1058人  未来可期me

iOS中长按图片保存到本地

- (void)viewDidLoad {

[super viewDidLoad];

_testImageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

_testImageView.image = [UIImage imageNamed:@"test.jpg"];

_testImageView.userInteractionEnabled = YES;

[self.view addSubview:_testImageView];

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClicked:)];

[_testImageView addGestureRecognizer:longPress];

}


- (void)longPressClicked:(UILongPressGestureRecognizer *)longPress {

NSLog(@"press");

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

}



//实现imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:方法

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

{

if (!error) {

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

}else

{

message = [error description];

}

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

}

上一篇下一篇

猜你喜欢

热点阅读