Swift點(diǎn)擊瀏覽圖片

//

//ZScanImage.swift

//點(diǎn)擊展示圖片

//

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

//當(dāng)前image的原始尺寸->將像素currentImageview.bounds由currentImageview.bounds所在視圖轉(zhuǎn)換到目標(biāo)視圖window中,返回在目標(biāo)視圖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()

})

}

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1、設(shè)置UILabel行間距 NSMutableAttributedString* attrString = [[...
    十年一品溫如言1008閱讀 2,047評論 0 3
  • 在iOS中隨處都可以看到絢麗的動畫效果,實(shí)現(xiàn)這些動畫的過程并不復(fù)雜,今天將帶大家一窺iOS動畫全貌。在這里你可以看...
    F麥子閱讀 5,271評論 5 13
  • 1、禁止手機(jī)睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa閱讀 1,211評論 1 6
  • 1、改變 UITextField 占位文字 顏色和去掉底部白框 [_userName setValue:[UICo...
    i_MT閱讀 1,193評論 0 2
  • 軌道注定偏移 相愛注定分離 視線寧死不愿消遺 白發(fā)掩飾流浪 皺紋掩飾絕望 月光無法漂白悲愴 全力否認(rèn)愛戀 安慰殺死...
    天涯葉開閱讀 272評論 2 2

友情鏈接更多精彩內(nèi)容