侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

高仿QQ、微信用户图像处理

2024-05-14 星期二 / 0 评论 / 0 点赞 / 81 阅读 / 5452 字

// .h文件 #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface ImageDandleTool : NSO

// .h文件

 

#import <Foundation/Foundation.h>

#import <UIKit/UIKit.h>

 

@interface ImageDandleTool : NSObject

// 获取控件的坐标,传入用户图片

-(void)fullScreenWithUIView:(UIView *)view Image:(UIImage *)UserImage;

@end

 

// .m

#import "ImageDandleTool.h"

 

@interface ImageDandleTool ()<UIScrollViewDelegate>

 

@end

static CGRect oldFrame;

@implementation ImageDandleTool

 

-(void)fullScreenWithUIView:(UIView *)view Image:(UIImage *)UserImage{

    UIImage *image = UserImage;

    UIWindow *window = [UIApplication sharedApplication].keyWindow;

    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];

    scrollView.maximumZoomScale = 1.5;

    scrollView.minimumZoomScale = 1.0;

    scrollView.bounces = NO;

    scrollView.delegate = self;

//    坐标系的转化,将控件的坐标转换成目标视图中的坐标;

    oldFrame = [view convertRect:view.bounds toView:window];

    scrollView.backgroundColor = [UIColor blackColor];

    scrollView.alpha = 0;

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:oldFrame];

    imageView.image = image;

    imageView.tag = 1;

    [scrollView addSubview:imageView];

    [window addSubview:scrollView];

    //    添加点击手势;

    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(fullScreenTapGR:)];

    [scrollView addGestureRecognizer: tap];

    [UIView animateWithDuration:0.3 animations:^{

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

        scrollView.alpha=1;

    }

                     completion:^(BOOL finished) {

                     }];

    //    添加双击的手势;

    UITapGestureRecognizer *tapTwo = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapTwoAction:)];

    tapTwo.numberOfTapsRequired = 2;

    [scrollView addGestureRecognizer:tapTwo];

    //    当双击手势和单击手势共存的时候,只有没有检测到双击手势的时候,单击才有效;

    [tap requireGestureRecognizerToFail:tapTwo];

}

//双击手势触发的方法;

-(void)tapTwoAction:(UITapGestureRecognizer *)sender{

    UIScrollView *scrollView = (UIScrollView *)sender.view;

    if (scrollView.zoomScale <= 1.0) {

        [UIView animateWithDuration:0.3 animations:^{

            scrollView.zoomScale = 1.5;

        }];

    }else{

        [UIView animateWithDuration:0.3 animations:^{

            scrollView.zoomScale = 1.0;

        }];

    }

}

// 点击退回原来的图片;

-(void)fullScreenTapGR:(UITapGestureRecognizer*)tap{

    UIScrollView *backgroundView = (UIScrollView *)tap.view;

    UIImageView *imageView=(UIImageView*)[tap.view viewWithTag:1];

    [UIView animateWithDuration:0.3 animations:^{

        imageView.frame=oldFrame;

        backgroundView.alpha=0;

    }

                     completion:^(BOOL finished) {

                         [backgroundView removeFromSuperview];

                     }];

}

//返回要缩放的控件;

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

    return [scrollView viewWithTag:1];

}

//只要进行缩放,就会执行的该方法,使图片居中;

-(void)scrollViewDidZoom:(UIScrollView *)scrollView{

    CGPoint cender = scrollView.center;

    if (scrollView.zoomScale >1) {

        cender.x = [UIScreen mainScreen].bounds.size.width/2 +((scrollView.zoomScale - 1) * [UIScreen mainScreen].bounds.size.width/2);

        cender.y = [UIScreen mainScreen].bounds.size.height/2;

    }

    [scrollView viewWithTag:1].center = cender;

}

 

广告 广告

评论区