0
我用下面的代碼從互聯網上獲得的圖像如何在UITableViewCell中保存圖片到相冊與長按
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",image_url, [dic objectForKey:@"imageurl"]]];
__block UIActivityIndicatorView *activityIndicator;
__weak UIImageView *weakImageView = cell.userinformationimageView;
cell.userinformationimageView.backgroundColor = [UIColor clearColor];
[cell.userinformationimageView sd_setImageWithURL:imageUrl placeholderImage:nil options:SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) {
if (!activityIndicator) {
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]];
activityIndicator.center = weakImageView.center;
[activityIndicator startAnimating];
}
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}];
//more codes
}
有那麼多的細胞,每個單元都有一個形象,我添加長按
UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];
longPressGr.minimumPressDuration = 1.0;
[self.tableview addGestureRecognizer:longPressGr];
- (void)longPressToDo:(UILongPressGestureRecognizer *)gesture
{
if(gesture.state == UIGestureRecognizerStateBegan)
{
CGPoint point = [gesture locationInView:self.tableview];
NSIndexPath *indexPath = [self.tableview indexPathForRowAtPoint:point];
if(indexPath == nil) return;
NSLog(@"---->%d",[indexPath row]);
NSDictionary *dic = [self.tableData objectAtIndex:indexPath.row];
}
}
那麼如何獲得我長時間拍攝的圖像?我想將它保存到相冊中,謝謝。
添加函數'longpresstodo'不起作用。 – spotcool
ohh還有一件事,你需要設置爲UIImageView啓用交互,默認情況下它關閉。讓我修復答案 – Qazi
我編輯了答案,它是否適合你(我測試了它在我身邊,但只是好奇,如果我留下了一些東西) – Qazi