您的位置:首页 > 其它

长按保存图片到本地

2015-10-26 12:12 232 查看
//创建UILongPressGestureRecognizer

UILongPressGestureRecognizer
*longPG = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(longAction:)
];

[self
addGestureRecognizer:longPG];

}

//长按触发的方法

-(void)longAction:(UILongPressGestureRecognizer
*)longPG

{

if (longPG.state
==
UIGestureRecognizerStateBegan)

{

//创建UIAlertView对象

UIAlertView *alert = [[UIAlertView
alloc]initWithTitle:@"提示"
message:@"是否保存图片到本地"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",
nil];

//调用show方法

[alert
show];

//释放

[alert
release];

}

}

- (void)alertView:(UIAlertView
*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

if (buttonIndex ==
1) {

//UIImage写入本地的方法

UIImageWriteToSavedPhotosAlbum(self.photo.image,
nil,
nil,
nil);

//创建UIAlertView对象

UIAlertView *alert = [[UIAlertView
alloc]initWithTitle:@"提示"
message:@"图片已保存成功"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:
nil];

//调用show方法

[alert
show];

//释放

[alert
release];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(1.0f
*
NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{

[alert
dismissWithClickedButtonIndex:0
animated:YES];

});

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: