// // CommonViewToFill.swift // 给view绑定双击全屏事件 再次双击恢复 直接在init初始化即可 // // Created by Virgil on 2018/8/23. // Copyright © 2018年 Virgil. All rights reserved. // import UIKit class CommonViewToFill: NSObject { ///控制器View private var _vcView: UIView! ///当前View private var _currentView: UIView! ///父层View private var _parentView: UIView! ///默认是否显示导航栏 private var _defaultIsShowNav = true private var isFill = false private var vcViewFrame: CGRect! private var currentViewFrame: CGRect! /// vcView:self.view页面 currentView:要全屏的View defaultIsShowNav:默认是否显示导航栏 注:背景透明时全屏底下view会露出 init(vcView: UIView, currentView: UIView, defaultIsShowNav: Bool) { super.init() _vcView = vcView _currentView = currentView _defaultIsShowNav = defaultIsShowNav _parentView = _currentView.superview! let videoViewGesture = UITapGestureRecognizer(target: self, action: #selector(videoClick)) videoViewGesture.numberOfTapsRequired = 2 _currentView.addGestureRecognizer(videoViewGesture) } @objc func videoClick(sender: UITapGestureRecognizer) { setIsFill(isFill: isFill) isFill = !isFill } func setIsFill(isFill: Bool) { if isFill { UIApplication.shared.setStatusBarHidden(false, with: .none) _currentView.removeFromSuperview() _parentView.addSubview(_currentView) UIView.animate(withDuration: 0.4, animations: { appDelegate.setNavigationBarHidden(isHidden: !self._defaultIsShowNav) self._vcView.transform = CGAffineTransform.inverted(CGAffineTransform(rotationAngle: CGFloat(0)))() // self._vcView.frame = self.vcViewFrame self._currentView.frame = self.currentViewFrame }) { (_) in } } else { self.vcViewFrame = self._vcView.frame self.currentViewFrame = self._currentView.frame UIApplication.shared.setStatusBarHidden(true, with: .none) _currentView.removeFromSuperview() _vcView.addSubview(_currentView) _vcView.bringSubviewToFront(_currentView) UIView.animate(withDuration: 0.4, animations: { appDelegate.setNavigationBarHidden(isHidden: true) self._vcView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi/2)) self._vcView.frame = CGRect(x: 0, y: 0, width: ScreenHeight, height: ScreenWidth) self._currentView.frame = CGRect(x: 0, y: 0, width: ScreenHeight, height: ScreenWidth) }) { (_) in } } } }