关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回

iOS实现点击微信头像(放大、缩放、保存)效果

发布时间:2022-09-27 11:07:21

先来看看实现效果(GIF):

iOS实现点击微信头像(放大、缩放、保存)效果

实现思路:

直接自定义 UIView(CYPhotoPreviewer),为了实现双击缩放,可以实现 UIScrollViewDelegate 对应的方法。如果需要模糊背景,可以在自定义的 UIView 中先添加模糊背景,再添加 UIScrollView,继而在 UIScrollView 中添加图片容器,这个容器就是要显示的图片的 superView,代码一目了然:

- (void)setup {
 
 self.frame = [UIScreenmainScreen].bounds;
 self.backgroundColor = [UIColorclearColor];
 
 UITapGestureRecognizer *singleTap = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(singleTap:)];
 [self addGestureRecognizer:singleTap];
 
 UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(doubleTap:)];
 doubleTap.numberOfTapsRequired = 2;
 [singleTaprequireGestureRecognizerToFail:doubleTap];
 [self addGestureRecognizer:doubleTap];
 
 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizeralloc] initWithTarget:selfaction:@selector(longPress:)];
 [self addGestureRecognizer:longPress];
 
 // 设置模糊背景
 self.blurBackground = [[UIVisualEffectViewalloc] initWithEffect:[UIBlurEffecteffectWithStyle:UIBlurEffectStyleExtraLight]];
 self.blurBackground.frame = self.frame;
 [self addSubview:self.blurBackground];
 
 // 设置 UIScrollView 相关属性
 self.scrollView = [[UIScrollViewalloc] initWithFrame:[UIScreenmainScreen].bounds];
 self.scrollView.delegate = self;
 self.scrollView.bouncesZoom = YES;
 self.scrollView.maximumZoomScale = 3.0;
 self.scrollView.multipleTouchEnabled = YES;
 self.scrollView.alwaysBounceVertical = NO;
 self.scrollView.showsVerticalScrollIndicator = NO;
 self.scrollView.showsHorizontalScrollIndicator = NO;
 [self addSubview:self.scrollView];
 
 // containerView
 self.containerView = [[UIViewalloc] init];
 [self.scrollViewaddSubview:self.containerView];
 
 // imageView
 self.imageView = [[UIImageViewalloc] init];
 self.imageView.clipsToBounds = YES;
 self.imageView.backgroundColor = [UIColorcolorWithWhite:1.0 alpha:0.5];
 [self.containerViewaddSubview:self.imageView];
}

另外有需要云服务器可以了解下风纳云fengnayun.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


/template/Home/Dawn/PC/Static

选择风纳云,也许是您成就一番大事业的开端

注册账号