iOS长按保存图片
来源:互联网 发布:知其雄兮守其雌 编辑:程序博客网 时间:2024/04/28 04:37
在有的App中的图片你长按它就会提示你是否保存当前图片,这个效果看起来是不是挺高大上的啊,今天我就来给大家分享这个效果,下面写代码
下面的代码中imageView得首先创建好,就是你想要保存的那种图片,都在viewDidLoad中写
// 长按(longPress)
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizeralloc] initWithTarget:selfaction:@selector(longPressAction:)];
[imageViewaddGestureRecognizer:longPress];
// 判定为长按手势 需要的时间
longPress.minimumPressDuration =1;
// 判断期间,允许用户移动的距离
longPress.allowableMovement =100;
// 长按的手势
- (void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
// 手势的状态
if (longPress.state ==UIGestureRecognizerStateBegan) {
//当手势的状态处于刚开始的状态
self.myAlertView = [[UIAlertViewalloc] initWithTitle:@"提示"message:@"您要保存当前图片到相册中吗?"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"保存",nil];
[self.myAlertViewshow];
[_myAlertViewrelease];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
// 保存照片
NSInteger i =self.scroll.contentOffset.x /self.scroll.bounds.size.width;
UIImageView *myImageView = (UIImageView *)[self.viewviewWithTag:10000 + i];
UIImageWriteToSavedPhotosAlbum(myImageView.image,self, @selector(image:didFinshSavingWithError:contextInfo:),nil);
}
}
// 保存图片错误提示方法
- (void)image:(UIImage *)image didFinshSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
NSString *mes = nil;
if (error != nil) {
mes =@"保存图片失败";
}else {
mes =@"保存图片成功";
}
self.myAlertView2 = [[UIAlertViewalloc] initWithTitle:@"提示"message:mes delegate:selfcancelButtonTitle:nilotherButtonTitles:nil];
[self.myAlertView2show];
[_myAlertView2release];
[NSTimerscheduledTimerWithTimeInterval:0.8ftarget:selfselector:@selector(performDismiss:)userInfo:nilrepeats:NO];
}
- (void)performDismiss:(NSTimer *)timer
{
[self.myAlertView2dismissWithClickedButtonIndex:0animated:YES];
}
今天的代码就给大家分享到这,谢谢大家!
- iOS长按保存图片
- iOS长按图片保存实现方法
- iOS 长按图片保存本地
- iOS、长按webView 保存图片
- ios uiwebview 长按图片,保存到本地相册
- ios uiwebview 长按图片,保存到本地相册
- ios uiwebview 长按图片,保存到本地相册
- iOS开发 长按图片保存到相册
- ios APPweb网页长按识别二维码和保存图片
- iOS_长按保存图片
- webview长按保存图片
- UIWebView长按保存图片
- Android长按保存图片
- 长按图片保存图片到相册
- iOS开发截屏并保存图片到本地相册以及长按保存图片到本地
- 长按保存图片到本地
- UIWebView长按图片生成保存菜单
- Android 的WebView长按保存图片
- STL insert() demo
- Ruby Digest
- POJ 3279 Fliptile
- 利用android monkey 抢支付宝红包
- 【Java】浅谈JDBC事务处理
- iOS长按保存图片
- HDU-Can you solve this equation? -二分法求高次方程近似解
- http和socket简介
- Machine Learning - VIII. Neural Networks Representation神经网络的表示 (Week 4)
- 安卓之WebView的使用小结
- 毕设记录
- [linux device driver] Chapter 03:scullc_open理解
- iOS求职之C语言面试题
- Android WebView使用之JavaScript调用Java代码注意事项