点击头像单独把图片拉取出来.然后再次点击回到初始效果

本文介绍了一个iOS应用中实现图片点击放大预览的功能。通过使用UITapGestureRecognizer手势识别器,当用户点击图片时,图片会从表格单元格中弹出并全屏显示。同时,文章还实现了点击全屏图片时返回原始大小的效果。
长按保存效果未做
 
CGRect frame_first;
    UIImageView *fullImageView;
    UIImageView *photoImage;
 
- (void)imageTap:(UITapGestureRecognizer *)sender {
   
    CGPoint location = [sender locationInView:self.tableView];
   
    NSIndexPath *indexPath  = [self.tableView indexPathForRowAtPoint:location];
   
    UITableViewCell *cell = (UITableViewCell *)[self.tableView  cellForRowAtIndexPath:indexPath];
   
    UIImageView *imageV = (UIImageView *)[cell.contentView viewWithTag:9999];
   
    frame_first = CGRectMake(cell.frame.origin.x + imageV.frame.origin.x, cell.frame.origin.y + imageV.frame.origin.y - self.tableView.contentOffset.y, imageV.frame.size.width, imageV.frame.size.height);
   
    fullImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    fullImageView.backgroundColor=[UIColor blackColor];
    fullImageView.userInteractionEnabled=YES;
    [fullImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap2:)]];
    fullImageView.contentMode=UIViewContentModeScaleAspectFit;
    photoImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 84, 84)];
    NSDictionary *userPhoDic = [_dataHandle getLocalData:USERIMAGE];
    NSData *da = [userPhoDic objectForKey:@"image"];
    photoImage.image = [UIImage imageWithData:da];
    [fullImageView addSubview:photoImage];
    if (![fullImageView superview]) {
        [self.view.window addSubview:fullImageView];
        fullImageView.frame = frame_first;
        [UIView animateWithDuration:0.5 animations:^{
            fullImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            photoImage.frame = CGRectMake((SCREEN_WIDTH - 54) / 2, (SCREEN_HEIGHT - 54) / 2, 84, 84);
        } completion:^(BOOL finished) {
            [UIApplication sharedApplication].statusBarHidden=YES;
        }];
    }
}

-(void)actionTap2:(UITapGestureRecognizer *)sender{
   
    [UIView animateWithDuration:0.5 animations:^{
        fullImageView.frame = frame_first;
        photoImage.frame = CGRectMake(0, 0, 54, 54);
    } completion:^(BOOL finished) {
        [fullImageView removeFromSuperview];
    }];
    [UIApplication sharedApplication].statusBarHidden = NO;
}

转载于:https://www.cnblogs.com/tian-sun/p/4849751.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值