//
//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()
})
}
}