Forráskód Böngészése

空title时修正UI;修改切换前后台时播放问题

huzhiqiang 3 éve
szülő
commit
fdbbd76589

+ 17 - 9
MusicVideoPlus/AppDelegate.swift

@@ -56,8 +56,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
     func application(_: UIApplication, open url: URL, sourceApplication _: String?, annotation _: Any) -> Bool {
         return PQSingletoWXApiUtil.shared.handleOpen(url: url)
     }
-
-    func applicationDidEnterBackground(_: UIApplication) {
+    
+    func applicationWillResignActive(_ application: UIApplication) {
         BFLog(message: "applicationDidEnterBackground")
         DispatchQueue.global().asyncAfter(deadline: DispatchTime.now() + 1) {
             // 继续播放其他音乐
@@ -69,18 +69,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
             }
         }
     }
-
-    func applicationDidBecomeActive(_: UIApplication) {
+    func applicationWillEnterForeground(_ application: UIApplication) {
         BFLog(message: "applicationDidBecomeActive")
         DispatchQueue.global().async {
             let session = AVAudioSession.sharedInstance()
             do {
                 try session.setCategory(.playback)
-                BFLog(message: "打开声音活跃关闭其他音乐播放成功")
-            } catch {
-                BFLog(message: "打开声音活跃关闭其他音乐播放失败:\(error)")
-            }
-            do {
                 try session.setActive(true, options: .notifyOthersOnDeactivation)
                 BFLog(message: "打开声音活跃关闭其他音乐播放成功")
             } catch {
@@ -88,4 +82,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
             }
         }
     }
+
+    func applicationDidBecomeActive(_: UIApplication) {
+//        BFLog(message: "applicationDidBecomeActive")
+//        DispatchQueue.global().async {
+//            let session = AVAudioSession.sharedInstance()
+//            do {
+//                try session.setCategory(.playback)
+//                try session.setActive(true, options: .notifyOthersOnDeactivation)
+//                BFLog(message: "打开声音活跃关闭其他音乐播放成功")
+//            } catch {
+//                BFLog(message: "打开声音活跃关闭其他音乐播放失败:\(error)")
+//            }
+//        }
+    }
 }

+ 4 - 2
MusicVideoPlus/Classes/Modules/Home/Controllers/MVHomeController.swift

@@ -139,8 +139,10 @@ class MVHomeController: MVBaseController {
 
         controlPlayrPasueOrResume(isPause: false)
 
-        PQNotification.addObserver(self, selector: #selector(enterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
-        PQNotification.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
+//        PQNotification.addObserver(self, selector: #selector(enterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
+//        PQNotification.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)
+        PQNotification.addObserver(self, selector: #selector(enterBackground), name: UIApplication.willResignActiveNotification, object: nil)
+        PQNotification.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.didBecomeActiveNotification, object: nil)
     }
 
     override func viewWillDisappear(_ animated: Bool) {

+ 2 - 2
MusicVideoPlus/Classes/Modules/Home/Views/Banner/MVBanner.swift

@@ -203,7 +203,7 @@ public extension MVBanner {
             let page = self?.realIndex(index: index) ?? 0
             self?.setCurrentPage(page)
         })
-      
+        self.currentIndex = index
     }
 }
 
@@ -236,7 +236,7 @@ extension MVBanner: UIScrollViewDelegate {
     public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
         if(velocity.x > 0) {
             self.currentIndex += 1
-        }
+        } 
         else if (velocity.x < 0) {
             self.currentIndex -= 1
         }

+ 10 - 9
MusicVideoPlus/Classes/Modules/Home/Views/MVBannerCell.swift

@@ -78,8 +78,9 @@ class MVBannerCell: UICollectionViewCell {
         let titleLabel = UILabel()
         titleLabel.textAlignment = .left
         titleLabel.textColor = .white
-        titleLabel.numberOfLines=0
+        titleLabel.numberOfLines = 0
         titleLabel.lineBreakMode = .byCharWrapping
+        titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
         titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .bold)
         return titleLabel
     }()
@@ -199,17 +200,10 @@ class MVBannerCell: UICollectionViewCell {
        let textSize =  sizeWithText(text: videoData?.title ?? "", font: UIFont.systemFont(ofSize: 16, weight: .bold), size: CGSize.init(width:     self.frame.width -  24, height: CGFloat.greatestFiniteMagnitude))
         
         BFLog(message: "XXXXXXX videoData?.title is \(String(describing: videoData?.title)) height \(textSize.height)  width is \(adapterWidth(width: 300))")
-        titleLabel.snp.remakeConstraints { make in
-            make.width.equalTo(   self.frame.width -  24)
-            make.height.equalTo(textSize.height + 2)
-            make.left.equalToSuperview().offset(12)
-            make.bottom.equalTo(musicContenView.snp_top).offset(-cDefaultMargin)
-        }
+
         BFLog(message: "videoData?.title is \(String(describing: videoData?.title)) height \(textSize.height)")
         titleLabel.text = videoData?.title ?? ""
    
-
-        
 //        if videoData?.categoryImage != nil {
 //            typeImage.setNetImage(url: "\(videoData?.categoryImage ?? "")", placeholder: UIImage(named: "categary_icon")!)
 //        } else {
@@ -290,6 +284,13 @@ class MVBannerCell: UICollectionViewCell {
             make.left.equalTo(musicImageView.snp_centerX)
             make.right.top.height.equalToSuperview()
         }
+        
+        titleLabel.snp.remakeConstraints { make in
+            make.width.equalToSuperview().offset(-24)
+//            make.height.equalTo(textSize.height + 2)
+            make.left.equalToSuperview().offset(12)
+            make.bottom.equalTo(musicContenView.snp_top).offset(-cDefaultMargin - 2)
+        }
 
 //        if(videoData?.title?.count ?? 0 > 0){
 //            typeImage.snp.remakeConstraints { make in