无故事王国
2024-03-13 919d1d6bb0ec4043ec25b58a492618239ca37529
WanPai/Root/Course/VC/CourseVC.swift
@@ -12,98 +12,98 @@
class CourseVC: BaseVC {
    @IBOutlet weak var scrollView: CourseScrollView!
    @IBOutlet weak var view_container: UIView!
    @IBOutlet weak var btn_addStudent: QMUIButton!
    @IBOutlet weak var img_bg: UIImageView!
    @IBOutlet weak var cons_imgHeight: NSLayoutConstraint!
   private var imgSize:CGSize =  .zero
            @IBOutlet weak var scrollView: CourseScrollView!
            @IBOutlet weak var view_container: UIView!
            @IBOutlet weak var btn_addStudent: QMUIButton!
            @IBOutlet weak var img_bg: UIImageView!
            @IBOutlet weak var cons_imgHeight: NSLayoutConstraint!
            private var imgSize:CGSize =  .zero
    var startClouseHomeModel:StartClouseHomeModel?
            var startClouseHomeModel:StartClouseHomeModel?
    override func viewDidLoad() {
      super.viewDidLoad()
            override func viewDidLoad() {
                        super.viewDidLoad()
    }
   override func viewDidAppear(_ animated: Bool) {
      super.viewDidAppear(animated)
      guard !children.contains(where: {$0 is CourseInfoVC}) else {return}
      Services.startCourseHome().subscribe(onNext: {[weak self] data in
         if let model = data.data{
            if model.isThere == 1{
               UserDefaults.standard.setValue(model.stuId, forKey: "currentStuId")
               UserDefaults.standard.synchronize()
               let courseInfoVC = CourseInfoVC()
               courseInfoVC.startClouseHomeModel = model
               self?.addChild(courseInfoVC)
               courseInfoVC.view.frame = self?.view.frame ?? .zero
               self?.view.addSubview(courseInfoVC.view)
               self?.didMove(toParent: courseInfoVC)
            }
            self?.img_bg.sd_setImage(with: URL(string: model.imgs)) {[weak self] image, error, type, url in
               if let image{
                  self?.img_bg.image = image
                  let radio = image.size.width / image.size.height
                  self?.cons_imgHeight.constant = JQ_ScreenW / radio
               }
            override func viewDidAppear(_ animated: Bool) {
                        super.viewDidAppear(animated)
                        guard !children.contains(where: {$0 is CourseInfoVC}) else {return}
                        Services.startCourseHome().subscribe(onNext: {[weak self] data in
                                    if let model = data.data{
                                                if model.isThere == 1{
                                                            UserDefaults.standard.setValue(model.stuId, forKey: "currentStuId")
                                                            UserDefaults.standard.synchronize()
                                                            let courseInfoVC = CourseInfoVC()
                                                            courseInfoVC.startClouseHomeModel = model
                                                            self?.addChild(courseInfoVC)
                                                            courseInfoVC.view.frame = self?.view.frame ?? .zero
                                                            self?.view.addSubview(courseInfoVC.view)
                                                            self?.didMove(toParent: courseInfoVC)
                                                }
                                                self?.img_bg.sd_setImage(with: URL(string: model.imgs)) {[weak self] image, error, type, url in
                                                            if let image{
                                                                        self?.img_bg.image = image
                                                                        let radio = image.size.width / image.size.height
                                                                        self?.cons_imgHeight.constant = JQ_ScreenW / radio
                                                            }
                                                }
                                    }
                        }).disposed(by: disposeBag)
            }
         }
      }).disposed(by: disposeBag)
   }
            override func setUI() {
                        scrollView.bounces = false
                        btn_addStudent.imagePosition = .left
                        btn_addStudent.spacingBetweenImageAndTitle = 0
                        btn_addStudent.imageEdgeInsets = UIEdgeInsets(top: 3, left: 0, bottom: 0, right: 0)
                        cons_imgHeight.constant =  JQ_ScreenH * imgSize.width / JQ_ScreenW
                        scrollView.contentInset = UIEdgeInsets( top: JQ_ScreenW * 0.6794 - JQ_NavBarHeight - 20, left: 0, bottom: 0, right: 0)
            }
    override func setUI() {
        scrollView.bounces = false
        btn_addStudent.imagePosition = .left
        btn_addStudent.spacingBetweenImageAndTitle = 0
        btn_addStudent.imageEdgeInsets = UIEdgeInsets(top: 3, left: 0, bottom: 0, right: 0)
        cons_imgHeight.constant =  JQ_ScreenH * imgSize.width / JQ_ScreenW
        scrollView.contentInset = UIEdgeInsets( top: JQ_ScreenW * 0.6794 - JQ_NavBarHeight - 20, left: 0, bottom: 0, right: 0)
    }
            override func setRx() {
                        //        NotificationCenter.default.rx.notification(StudentUpdate_Nofi).take(until: self.rx.deallocated).subscribe(onNext: { [weak self] data in
                        //            guard let weakSelf = self else { return }
                        //            Services.startCourseHome().subscribe(onNext: {[weak self] data in
                        //            if let model = data.data{
                        //               if model.isThere == 1{
                        //                  UserDefaults.standard.setValue(model.stuId, forKey: "currentStuId")
                        //                  UserDefaults.standard.synchronize()
                        //                  let courseInfoVC = CourseInfoVC()
                        //                  courseInfoVC.startClouseHomeModel = model
                        //                  let clouseNav = BaseNav(rootViewController: courseInfoVC)
                        //                  clouseNav.tabBarItem = UITabBarItem(title: "玩湃运动营", image: UIImage(named: "tabbar_course"), selectedImage: UIImage(named: "tabbar_course_s")!.withRenderingMode(.alwaysOriginal))
                        //                  self?.tabBarController?.viewControllers![1] = clouseNav
                        //               }else{
                        //                  let courseVC = CourseVC()
                        //                  courseVC.startClouseHomeModel = model
                        //                  let clouseNav = BaseNav(rootViewController: courseVC)
                        //                  clouseNav.tabBarItem = UITabBarItem(title: "玩湃运动营", image: UIImage(named: "tabbar_course"), selectedImage: UIImage(named: "tabbar_course_s")!.withRenderingMode(.alwaysOriginal))
                        //                  self?.tabBarController?.viewControllers![1] = clouseNav
                        //               }
                        //                }
                        //            }).disposed(by: weakSelf.disposeBag)
                        //        }).disposed(by: disposeBag)
            }
    override func setRx() {
//        NotificationCenter.default.rx.notification(StudentUpdate_Nofi).take(until: self.rx.deallocated).subscribe(onNext: { [weak self] data in
//            guard let weakSelf = self else { return }
//            Services.startCourseHome().subscribe(onNext: {[weak self] data in
//            if let model = data.data{
//               if model.isThere == 1{
//                  UserDefaults.standard.setValue(model.stuId, forKey: "currentStuId")
//                  UserDefaults.standard.synchronize()
//                  let courseInfoVC = CourseInfoVC()
//                  courseInfoVC.startClouseHomeModel = model
//                  let clouseNav = BaseNav(rootViewController: courseInfoVC)
//                  clouseNav.tabBarItem = UITabBarItem(title: "玩湃运动营", image: UIImage(named: "tabbar_course"), selectedImage: UIImage(named: "tabbar_course_s")!.withRenderingMode(.alwaysOriginal))
//                  self?.tabBarController?.viewControllers![1] = clouseNav
//               }else{
//                  let courseVC = CourseVC()
//                  courseVC.startClouseHomeModel = model
//                  let clouseNav = BaseNav(rootViewController: courseVC)
//                  clouseNav.tabBarItem = UITabBarItem(title: "玩湃运动营", image: UIImage(named: "tabbar_course"), selectedImage: UIImage(named: "tabbar_course_s")!.withRenderingMode(.alwaysOriginal))
//                  self?.tabBarController?.viewControllers![1] = clouseNav
//               }
//                }
//            }).disposed(by: weakSelf.disposeBag)
//        }).disposed(by: disposeBag)
    }
    @IBAction func addStudentAction(_ sender: QMUIButton) {
        let addstudentVC = AddStudentVC(type: .course)
        push(vc: addstudentVC)
    }
            @IBAction func addStudentAction(_ sender: QMUIButton) {
                        let addstudentVC = AddStudentVC(type: .course)
                        push(vc: addstudentVC)
            }
}
public class CourseScrollView:UIScrollView{
    public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        for subView in subviews{
            let p = subView.convert(point, to: self)
            let hitTestView = subView.hitTest(p, with: event)
            return hitTestView
        }
        return nil
    }
            public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
                        for subView in subviews{
                                    let p = subView.convert(point, to: self)
                                    let hitTestView = subView.hitTest(p, with: event)
                                    return hitTestView
                        }
                        return nil
            }
}