时间:2021-05-20
如果你感觉累,那就对了那是因为你在走上坡路。。这句话似乎有点道理的样子,时常提醒自己无论走到哪都不要忘记自己当初为什么出发。有时想想感觉有的东西可以记录一下,就把它记录下来吧,这次想写一下关于单张图片点击全屏预览的问题,网上查了一些大神写的有的功能确实很强大但自己暂时想要的只是简单的功能就好,还有些方法自己也没弄出想要的效果,最后写了一个比较简单的点击单张图片的全屏预览和双指捏合缩小放大,可能有时要对图片做一些处理,这里放大后只是显示同一张图片并未做处理,下面直接贴出代码
//// ViewController.m// XWZoomImageView//// Created by xiao on 15/11/13.// Copyright © 2015年 xiao. All rights reserved.//#import "ViewController.h"@interface ViewController ()<UIScrollViewDelegate>@property (weak, nonatomic) IBOutlet UIImageView *picView;@property (weak, nonatomic) UIScrollView *scrollView;@property (weak, nonatomic) UIImageView *lastImageView;@property (nonatomic, assign)CGRect originalFrame;@property (nonatomic, assign)BOOL isDoubleTap;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.picView.userInteractionEnabled = YES; //添加单击手势 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showZoomImageView:)]; [self.picView addGestureRecognizer:tap]; }-(void)showZoomImageView:(UITapGestureRecognizer *)tap{ if (![(UIImageView *)tap.view image]) { return; } //scrollView作为背景 UIScrollView *bgView = [[UIScrollView alloc] init]; bgView.frame = [UIScreen mainScreen].bounds; bgView.backgroundColor = [UIColor blackColor]; UITapGestureRecognizer *tapBg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgView:)]; [bgView addGestureRecognizer:tapBg]; UIImageView *picView = (UIImageView *)tap.view; UIImageView *imageView = [[UIImageView alloc] init]; imageView.image = picView.image; imageView.frame = [bgView convertRect:picView.frame fromView:self.view]; [bgView addSubview:imageView]; [[[UIApplication sharedApplication] keyWindow] addSubview:bgView]; self.lastImageView = imageView; self.originalFrame = imageView.frame; self.scrollView = bgView; //最大放大比例 self.scrollView.maximumZoomScale = 1.5; self.scrollView.delegate = self; [UIView animateWithDuration:0.5 animations:^{ CGRect frame = imageView.frame; frame.size.width = bgView.frame.size.width; frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width); frame.origin.x = 0; frame.origin.y = (bgView.frame.size.height - frame.size.height) * 0.5; imageView.frame = frame; }];}-(void)tapBgView:(UITapGestureRecognizer *)tapBgRecognizer{ self.scrollView.contentOffset = CGPointZero; [UIView animateWithDuration:0.5 animations:^{ self.lastImageView.frame = self.originalFrame; tapBgRecognizer.view.backgroundColor = [UIColor clearColor]; } completion:^(BOOL finished) { [tapBgRecognizer.view removeFromSuperview]; self.scrollView = nil; self.lastImageView = nil; }];}//返回可缩放的视图-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{ return self.lastImageView;}最后同样带上一张图片吧,大致是这样子
再给大家分享一则IOS中点击图片后放大的代码
.h文件-----------------------------------------------------------------#import@interface ZoomImage : NSObject/** *@brief点击图片放大,再次点击缩小 * *@param oldImageView 头像所在的imageView */+(void)showImage:(UIImageView*)avatarImageView;@end.m文件-----------------------------------------------------------------#import "ZoomImage.h"static CGRect oldframe;@implementation ZoomImage+(void)showImage:(UIImageView*)avatarImageView{ UIImage *image =avatarImageView.image; // 获得根窗口 UIWindow *window =[UIApplication sharedApplication].keyWindow; UIView *backgroundView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)]; oldframe =[avatarImageView convertRect:avatarImageView.bounds toView:window]; backgroundView.backgroundColor =[UIColor blackColor]; backgroundView.alpha =0.5; UIImageView *imageView =[[UIImageView alloc]initWithFrame:oldframe]; imageView.image =image; imageView.tag =1; [backgroundView addSubview:imageView]; [window addSubview:backgroundView]; //点击图片缩小的手势 UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)]; [backgroundView 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); backgroundView.alpha =1; }];}+(void)hideImage:(UITapGestureRecognizer *)tap{ UIView *backgroundView =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]; }];}声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本篇效果利用HTML、CSS和Jq实现的图片点击预览功能,在预览时也可以点击切换图片。图片1为整体效果,图片2是点击图片1后出现被点击图片的预览图片的名称以
小知识wx.previewImage是微信小程序官方提供的预览图片功能的api。在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。那么
效果预览按下右侧的“点击预览”按钮可以在当前页面预览,点击链接可以全屏预览。https://codepen.io/comehope/pe
本文实例为大家分享了iOS实现视频播放和取消全屏功能具体代码,供大家参考,具体内容如下iOS视频播放全屏和取消全屏功能实现,所需全屏的视频所在的vc需要导航控制
手机图片预览photoswipe,支持pc图片预览,多用于android,ios的手机图片预览。资源包:photoswipe-3.0.5在photoswipe官