younger_times
2023-07-05 c5e94788e59723d189642e8489423ea64271340b
WanPai/Base/BaseVC.swift
@@ -40,21 +40,6 @@
    }
    func setRx(){
        NotificationCenter.default.rx.notification(UIDevice.orientationDidChangeNotification).take(until:self.rx.deallocated).subscribe {[weak self] _ in
            let orient = UIDevice.current.orientation
            var desc = ""
//            switch orient {
//                case .portrait :desc = Localized("屏幕正常竖向")
//                case .portraitUpsideDown:desc = Localized("屏幕倒立")
//                case .landscapeLeft:desc = Localized("屏幕左旋转")
//                case .landscapeRight:desc = Localized("屏幕右旋转")
//                default:break
//            }
            if !desc.isEmpty{
                self?.receiverNotification(orient: orient, desc: desc)
            }
        }.disposed(by: disposeBag)
    }
    func setUI(){
@@ -85,16 +70,24 @@
        navigationController?.popViewController(animated: true)
    }
    deinit {
        LogInfo(String(format: "%@ 已释放", NSStringFromClass(self.classForCoder).components(separatedBy: ".").last!))
    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        coordinator.animate(alongsideTransition: { [weak self] (context) in
            let orient = UIApplication.shared.statusBarOrientation
            switch orient {
            case .landscapeLeft, .landscapeRight:
                //横屏时禁止左拽滑出
                self?.navigationController?.interactivePopGestureRecognizer?.isEnabled = false
            default:
                //竖屏时允许左拽滑出
                self?.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
            }
        })
        super.viewWillTransition(to: size, with: coordinator)
    }
    /// 屏幕旋转:当设备方向改变,需要对UI进行重新布局,子类重写此方法
    @objc open func receiverNotification(orient:UIDeviceOrientation,desc:String){
        LogInfo(desc)
        refreshUI()
    deinit {
        LogInfo(String(format: "%@ 已释放", NSStringFromClass(self.classForCoder).components(separatedBy: ".").last!))
    }
}