头像点击放大 再点击时返回原来的位置 可以看看

来源:互联网 发布:python capitalize 编辑:程序博客网 时间:2024/06/09 22:08

/**

 *  保留原始时的位置

 */


static CGRect oldframe;

/**

 * @brief 浏览头像

 *

 * @param  oldImageView  头像所在的imageView

 */


+(void)showImage:(UIImageView *)avatarImageView{

    UIImage *image=avatarImageView.image;

    UIWindow *window=[UIApplicationsharedApplication].keyWindow;

    UIView *backgroundView=[[UIViewalloc]initWithFrame:CGRectMake(0,0, iphone_w,iphone_h)];

    oldframe=[avatarImageViewconvertRect:avatarImageView.boundstoView:window];//保存原始位置返回时要用

    backgroundView.backgroundColor=[UIColorgrayColor];

    backgroundView.alpha=0.3;

    UIImageView *imageView=[[UIImageViewalloc]initWithFrame:oldframe];

    imageView.image=image;

    imageView.tag=99;

    [backgroundView addSubview:imageView];

    [window addSubview:backgroundView];

    

    UITapGestureRecognizer *tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(hideImage:)];

    [backgroundView addGestureRecognizer: tap];//背景视图添加上手势,可以返回

    

    [UIViewanimateWithDuration:0.3animations:^{//动画

        imageView.frame=CGRectMake(0,([UIScreenmainScreen].bounds.size.height-image.size.height*[UIScreenmainScreen].bounds.size.width/image.size.width)/2, [UIScreen mainScreen].bounds.size.width, image.size.height*[UIScreenmainScreen].bounds.size.width/image.size.width);

        backgroundView.alpha=1;

    } completion:^(BOOL finished) {

        

    }];

}

+(void)hideImage:(UITapGestureRecognizer*)tap{

    UIView *backgroundView=tap.view;

    UIImageView *imageView=(UIImageView*)[tap.viewviewWithTag:99];

    [UIViewanimateWithDuration:0.3animations:^{

        imageView.frame=oldframe;//返回原始位置

        backgroundView.alpha=0;

    } completion:^(BOOL finished) {

        [backgroundView removeFromSuperview];//清除出视图

    }];

}


0 0
原创粉丝点击