Swift点击浏览图片

//

//ZScanImage.swift

//点击展示图片

//

//Created by zhaojinghao on 2017/8/10.

//Copyright © 2017年zhaojinghao. All rights reserved.

//

importUIKit

classZScanImage:NSObject{

var oldFrame:CGRect=CGRect.zero

func scanBigImageWithImageView(currentImageview:UIImageView) {

letimage = currentImageview.image

letwindow =UIApplication.shared.keyWindow

letbgView =UIView(frame:CGRect(x:0, y:0, width:UIScreen.main.bounds.width, height:UIScreen.main.bounds.height))

//当前image的原始尺寸->将像素currentImageview.bounds由currentImageview.bounds所在视图转换到目标视图window中,返回在目标视图window中的像素值

oldFrame= currentImageview.convert(currentImageview.bounds, to: window)

bgView.backgroundColor=UIColor.init(red:107/255.0, green:107/255.0, blue:99/255.0, alpha:0.5)

bgView.alpha=0

letimageView =UIImageView(frame:oldFrame)

imageView.image= image

imageView.tag=1024

bgView.addSubview(imageView)

window?.addSubview(bgView)

lettap =UITapGestureRecognizer.init(target:self, action:#selector(hideImageView(tap:)))

bgView.addGestureRecognizer(tap)

UIView.animate(withDuration:0.4, animations: {

vary,width,height:CGFloat//

height = image!.size.height*UIScreen.main.bounds.width/ image!.size.width

y = (UIScreen.main.bounds.height- height) *0.5

width =UIScreen.main.bounds.width

imageView.frame=CGRect(x:0, y: y, width: width, height: height)

bgView.alpha=1.0

}, completion: {

(result)in

})

}

funchideImageView(tap:UITapGestureRecognizer){

letbackGroundV = tap.view

letimageView = tap.view?.viewWithTag(1024)

UIView.animate(withDuration:0.4, animations: {

imageView?.frame=self.oldFrame

backGroundV?.alpha=0

}, completion: {

(result)in

backGroundV?.removeFromSuperview()

})

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    十年一品温如言1008阅读 1,705评论 0 3
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,141评论 5 13
  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 1,143评论 1 6
  • 1、改变 UITextField 占位文字 颜色和去掉底部白框 [_userName setValue:[UICo...
    i_MT阅读 1,059评论 0 2
  • 轨道注定偏移 相爱注定分离 视线宁死不愿消遗 白发掩饰流浪 皱纹掩饰绝望 月光无法漂白悲怆 全力否认爱恋 安慰杀死...
    天涯叶开阅读 232评论 2 2