• ios点击头像放大并能伸缩拖动


    点击头像放大,其实原理就是在头像处创建一个和头像一样大小的scrollview,然后让其放大至屏幕大小,点击屏幕取消时将其frame恢复之前大小,然后让其消失。

    1.首先创建头像和用来创建点击手势的视图

                AsyncImageView *touxiang=[[AsyncImageView alloc]init];
                touxiang.isAcceptTouch=YES;
                touxiang.tag=7758521;
                touxiang.frame=CGRectMake(SCREEN_WIDTH-80, 10, 40, 40);
                [touxiang setDefaultImageNameString:@"用户默认头像.png"];//默认图片
                [touxiang setFailLoadImageNameString:@"用户默认头像.png"];//加载失败的图片
                [touxiang loadImageFromURLString:[UtilityHelper getPicUrlByWidthAndHeight:@"" @"60" height:@"60"]];//图片的URL
                [self.contentView addSubview:touxiang];
                

                //加手势
                UIView *tapView=[[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-80, 10, 40, 40)];
                tapView.tag=7758520;
                tapView.backgroundColor=[UIColor clearColor];
                [self.contentView addSubview:tapView];
                UITapGestureRecognizer *tapG=[[UITapGestureRecognizer alloc]initWithTarget:(SouFunMyCountController *)parentCtr action:@selector(fangdaTx:)];
                tapG.delegate=(SouFunMyCountController *)parentCtr;
                [tapView addGestureRecognizer:tapG];

    2.在接收方法中处理图片

    //放大头像
    -(void)fangdaTx:(UITapGestureRecognizer *)sender
    {
        CGPoint SenderPoint = [sender locationInView:self.myCountTable];
        NSIndexPath * indexPath =[self.myCountTable.utilityTableView indexPathForRowAtPoint:SenderPoint];
        UITableViewCell * cell = [self.myCountTable.utilityTableView cellForRowAtIndexPath:indexPath];
        UIView * imageview = (UIView *)[self.myCountTable viewWithTag:7758520];
        AsyncImageView * asycimage = (AsyncImageView*)[self.myCountTable viewWithTag:7758521];
        

        //获取最开始头像位置
        self.originalFrame = CGRectMake(cell.frame.origin.x+imageview.frame.origin.x, cell.frame.origin.y+imageview.frame.origin.y-self.myCountTable.utilityTableView.contentOffset.y+64, imageview.frame.size.width, imageview.frame.size.height);
        
        
        self.imgHead=asycimage.image;
        
        if (self.scrollView==nil) {
            UIScrollView *sc=[[UIScrollView alloc]initWithFrame:self.originalFrame];
            sc.delegate=self;
            sc.contentSize=self.originalFrame.size;
            sc.backgroundColor=[UIColor blackColor];
            sc.maximumZoomScale=2;
            sc.minimumZoomScale=0.5;
            self.scrollView=sc;
            [self.view.window addSubview:self.scrollView];
        }
        
        UITapGestureRecognizer * gesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cancelTx)];
        [self.scrollView addGestureRecognizer:gesture];
        
        if (self.imgViewHead==nil) {
            UIImageView *imgV=[[UIImageView alloc]initWithImage:self.imgHead];
            imgV.frame=CGRectMake(0, 0, self.originalFrame.size.width, self.originalFrame.size.height);
            self.imgViewHead=imgV;
            [self.scrollView addSubview:self.imgViewHead];
        }
        
        [UIView animateWithDuration:0.2 animations:^{          //放大frame
            self.scrollView.frame=CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            self.imgViewHead.frame=CGRectMake((SCREEN_WIDTH-self.imgHead.size.width)/2, (SCREEN_HEIGHT-self.imgHead.size.height)/2, self.imgHead.size.width, self.imgHead.size.height);
          
            self.scrollView.contentSize=self.imgHead.size;
        } completion:^(BOOL finished) {
            
        }];
    }

    3.点击图片取消放大效果

    //取消头像弹窗
    -(void)cancelTx
    {
        [UIView animateWithDuration:0.2 animations:^{
            self.scrollView.frame=self.originalFrame;
            self.imgViewHead.frame=CGRectMake(0, 0, self.originalFrame.size.width, self.originalFrame.size.height);
            self.scrollView.contentSize=self.imgHead.size;
        } completion:^(BOOL finished) {
            [self.imgViewHead removeFromSuperview];
            [self.scrollView removeFromSuperview];
            self.imgViewHead=nil;
            self.scrollView=nil;
        }];
    }

    4.uiscrollview代理方法,用来处理缩放

    #pragma mark--scrollviewdelegate
    -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
    {
        return self.imgViewHead;
    }

    -(void)scrollViewDidZoom:(UIScrollView *)scrollView
    {
        self.imgViewHead.center=self.scrollView.center;
    }

  • 相关阅读:
    Delphi 实现任务栏多窗口图标显示
    Win7如何部署定制的Quicklaunch图标
    Delphi中关于菜单的几个技巧
    delphi里为程序任务栏右键菜单添加自定义菜单
    DELPHI 让子窗体显示在任务栏上
    C# Newtonsoft.Json 读取文件,返回json字符串
    C# Newtonsoft.Json 读取文件,返回json字符串
    在使用layui Table时,死活显示不了数据,无效的 JSON 基元 解决办法
    newtonsoft返回json去掉字符串
    ASP.NET MVC AJAX 请求中加入 antiforgerytoken 解决“所需的防伪表单字段“__RequestVerificationToken”不存在”问题
  • 原文地址:https://www.cnblogs.com/zhangkk/p/4633818.html
Copyright © 2020-2023  润新知