Parcourir la source

【2025】【View】View界面处理

niehaoyu il y a 4 mois
Parent
commit
c4db06bce3

+ 58 - 0
PDF Office/PDF Master/KMClass/KMPDFViewController/KMNDisplayViewController/KMNDisplayViewController.swift

@@ -8,6 +8,12 @@
 import Cocoa
 import KMComponentLibrary
 
+@objc protocol KMNDisplayViewControllerDelegate: AnyObject {
+    
+    @objc optional func displayViewControllerDidReadModeUpdated(_ controller: KMNDisplayViewController)
+ 
+}
+
 class KMNDisplayViewController: NSViewController {
 
     @IBOutlet var titleLabel: NSTextField!
@@ -32,9 +38,13 @@ class KMNDisplayViewController: NSViewController {
      
     @IBOutlet var themesBGView: NSView!
     @IBOutlet var themesLabel: NSTextField!
+    @IBOutlet var themesContendView: NSView!
     
     var pdfView: CPDFListView?
+    var viewManager: KMPDFViewManager?
     
+    weak open var delegate: KMNDisplayViewControllerDelegate?
+ 
     override func viewDidLoad() {
         super.viewDidLoad()
         // Do view setup here.
@@ -91,6 +101,9 @@ class KMNDisplayViewController: NSViewController {
                                                                   text: KMLocalizedString("Page Breaks"),
                                                                   checkboxType: .normal)
         
+        continueScrollCheckBox.setTarget(self, action: #selector(checkBoxClicked(_:)))
+        pageBreaksCheckBox.setTarget(self, action: #selector(checkBoxClicked(_:)))
+        
         noSplitSelector.setTarget(self, action: #selector(selectorClicked(_:)))
         verticalSelector.setTarget(self, action: #selector(selectorClicked(_:)))
         horizontalSelector.setTarget(self, action: #selector(selectorClicked(_:)))
@@ -135,11 +148,18 @@ class KMNDisplayViewController: NSViewController {
     @objc func selectorClicked(_ sender: ComponentCSelector) {
         if sender == singlePageSelector {
             
+            updatePDFViewDisplayInfo()
         } else if sender == twoPageSelector {
             
+            updatePDFViewDisplayInfo()
         } else if sender == bookSelector {
             
+            updatePDFViewDisplayInfo()
         } else if sender == readModeSelector {
+            if let manager = viewManager {
+                manager.isPDFReadMode = !manager.isPDFReadMode
+            }
+            delegate?.displayViewControllerDidReadModeUpdated?(self)
             
         } else if sender == fullScreenSelector {
             
@@ -152,7 +172,45 @@ class KMNDisplayViewController: NSViewController {
         } else if sender == horizontalSelector {
             
         }
+        
     }
     
+    @objc func checkBoxClicked(_ sender: ComponentCheckBox) {
+        if sender == continueScrollCheckBox {
+            updatePDFViewDisplayInfo()
+            
+        } else if sender == pageBreaksCheckBox {
+            pdfView?.displaysPageBreaks = pageBreaksCheckBox.properties.checkboxType == .selected ? true : false
+        }
+        
+    }
     
+    func updatePDFViewDisplayInfo() {
+        var pdfViewMode: CPDFDisplayViewMode = .singlePage
+        if singlePageSelector.properties.state == .pressed {
+            if continueScrollCheckBox.properties.checkboxType == .selected {
+                pdfViewMode = .singlePageContinuous
+            }
+            pdfView?.setDisplay(pdfViewMode)
+            
+        } else if twoPageSelector.properties.state == .pressed {
+            pdfViewMode = .twoUp
+            if continueScrollCheckBox.properties.checkboxType == .selected {
+                pdfViewMode = .twoUpContinuous
+            }
+            pdfView?.setDisplay(pdfViewMode)
+            
+        } else if bookSelector.properties.state == .pressed {
+            //书本模式
+            pdfView?.displaysAsBook = true
+            pdfView?.displayTwoUp = true
+            if continueScrollCheckBox.properties.checkboxType == .selected {
+                pdfView?.displayDirection = .vertical
+            } else {
+                pdfView?.displayDirection = .horizontal
+            }
+            
+        }
+    }
+
 }

+ 53 - 7
PDF Office/PDF Master/KMClass/KMPDFViewController/KMNDisplayViewController/KMNDisplayViewController.xib

@@ -22,6 +22,7 @@
                 <outlet property="splitViewBGView" destination="LAG-N5-iQ3" id="NWE-79-AdS"/>
                 <outlet property="splitViewLabel" destination="kaU-qa-1I7" id="JiC-SI-iJ2"/>
                 <outlet property="themesBGView" destination="zPv-9H-oej" id="jum-YR-HEE"/>
+                <outlet property="themesContendView" destination="dI8-s8-38t" id="JCh-oo-u7Q"/>
                 <outlet property="themesLabel" destination="tld-Xn-Y44" id="d2c-xg-Un2"/>
                 <outlet property="titleLabel" destination="8DM-Rh-5sB" id="4CW-pX-tLn"/>
                 <outlet property="twoPageSelector" destination="cRu-yj-3rx" id="M5y-Nm-K64"/>
@@ -183,10 +184,10 @@
                                         </constraints>
                                     </customView>
                                     <customView translatesAutoresizingMaskIntoConstraints="NO" id="LAG-N5-iQ3">
-                                        <rect key="frame" x="15" y="344" width="232" height="90"/>
+                                        <rect key="frame" x="15" y="188" width="232" height="246"/>
                                         <subviews>
                                             <customView translatesAutoresizingMaskIntoConstraints="NO" id="LSZ-mG-8Wk">
-                                                <rect key="frame" x="0.0" y="50" width="232" height="40"/>
+                                                <rect key="frame" x="0.0" y="206" width="232" height="40"/>
                                                 <subviews>
                                                     <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kaU-qa-1I7">
                                                         <rect key="frame" x="10" y="12" width="64" height="16"/>
@@ -204,44 +205,80 @@
                                                 </constraints>
                                             </customView>
                                             <customView translatesAutoresizingMaskIntoConstraints="NO" id="yhM-DQ-mT8" customClass="ComponentCSelector" customModule="KMComponentLibrary">
-                                                <rect key="frame" x="0.0" y="0.0" width="72" height="50"/>
+                                                <rect key="frame" x="0.0" y="156" width="72" height="50"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="72" id="2HG-BW-VOB"/>
                                                     <constraint firstAttribute="height" constant="50" id="9h4-8Z-eUY"/>
                                                 </constraints>
                                             </customView>
                                             <customView translatesAutoresizingMaskIntoConstraints="NO" id="GtB-mX-v1C" customClass="ComponentCSelector" customModule="KMComponentLibrary">
-                                                <rect key="frame" x="80" y="0.0" width="72" height="50"/>
+                                                <rect key="frame" x="80" y="156" width="72" height="50"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="72" id="5zh-ma-B1s"/>
                                                     <constraint firstAttribute="height" constant="50" id="Z5b-Bp-a9q"/>
                                                 </constraints>
                                             </customView>
                                             <customView translatesAutoresizingMaskIntoConstraints="NO" id="69S-Bx-TPQ" customClass="ComponentCSelector" customModule="KMComponentLibrary">
-                                                <rect key="frame" x="160" y="0.0" width="72" height="50"/>
+                                                <rect key="frame" x="160" y="156" width="72" height="50"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="72" id="ByQ-dX-HLN"/>
                                                     <constraint firstAttribute="height" constant="50" id="XAV-15-t4p"/>
                                                 </constraints>
                                             </customView>
+                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="RxL-qE-G5e" customClass="ComponentButton" customModule="KMComponentLibrary">
+                                                <rect key="frame" x="0.0" y="116" width="232" height="32"/>
+                                                <constraints>
+                                                    <constraint firstAttribute="height" constant="32" id="91F-D0-pDy"/>
+                                                </constraints>
+                                            </customView>
+                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="38q-hq-5aP">
+                                                <rect key="frame" x="0.0" y="72" width="232" height="36"/>
+                                                <constraints>
+                                                    <constraint firstAttribute="height" constant="36" id="Ul4-Vl-4gv"/>
+                                                </constraints>
+                                            </customView>
+                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="YvZ-Co-HOc" customClass="ComponentCheckBox" customModule="KMComponentLibrary">
+                                                <rect key="frame" x="0.0" y="0.0" width="232" height="32"/>
+                                                <constraints>
+                                                    <constraint firstAttribute="height" constant="32" id="pOT-Tx-B0Z"/>
+                                                </constraints>
+                                            </customView>
+                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="aKo-zY-Gp8" customClass="ComponentCheckBox" customModule="KMComponentLibrary">
+                                                <rect key="frame" x="0.0" y="32" width="232" height="32"/>
+                                                <constraints>
+                                                    <constraint firstAttribute="height" constant="32" id="h7G-3j-H1j"/>
+                                                </constraints>
+                                            </customView>
                                         </subviews>
                                         <constraints>
+                                            <constraint firstAttribute="trailing" secondItem="38q-hq-5aP" secondAttribute="trailing" id="1kf-NU-ogL"/>
                                             <constraint firstItem="GtB-mX-v1C" firstAttribute="top" secondItem="LSZ-mG-8Wk" secondAttribute="bottom" id="1rR-Vc-JGQ"/>
                                             <constraint firstItem="yhM-DQ-mT8" firstAttribute="top" secondItem="LSZ-mG-8Wk" secondAttribute="bottom" id="4Qs-s2-pUB"/>
+                                            <constraint firstItem="aKo-zY-Gp8" firstAttribute="leading" secondItem="LAG-N5-iQ3" secondAttribute="leading" id="5sp-Tq-c1O"/>
                                             <constraint firstAttribute="width" constant="232" id="7Gd-Cy-NXs"/>
-                                            <constraint firstAttribute="height" constant="90" id="8Rn-lw-8w1"/>
+                                            <constraint firstAttribute="trailing" secondItem="YvZ-Co-HOc" secondAttribute="trailing" id="7Kk-yn-FO4"/>
+                                            <constraint firstAttribute="height" constant="246" id="8Rn-lw-8w1"/>
                                             <constraint firstItem="GtB-mX-v1C" firstAttribute="top" secondItem="LSZ-mG-8Wk" secondAttribute="bottom" id="CGm-Uh-gDr"/>
+                                            <constraint firstItem="YvZ-Co-HOc" firstAttribute="top" secondItem="aKo-zY-Gp8" secondAttribute="bottom" id="EKg-yL-FG3"/>
+                                            <constraint firstItem="RxL-qE-G5e" firstAttribute="top" secondItem="yhM-DQ-mT8" secondAttribute="bottom" constant="8" id="FsP-BF-3yL"/>
+                                            <constraint firstItem="YvZ-Co-HOc" firstAttribute="leading" secondItem="LAG-N5-iQ3" secondAttribute="leading" id="GKw-i5-pXo"/>
+                                            <constraint firstAttribute="trailing" secondItem="RxL-qE-G5e" secondAttribute="trailing" id="Gz1-fQ-fJU"/>
                                             <constraint firstItem="LSZ-mG-8Wk" firstAttribute="leading" secondItem="LAG-N5-iQ3" secondAttribute="leading" id="Jmd-Vu-uzi"/>
                                             <constraint firstItem="69S-Bx-TPQ" firstAttribute="top" secondItem="LSZ-mG-8Wk" secondAttribute="bottom" id="MbM-X0-YxC"/>
                                             <constraint firstItem="LSZ-mG-8Wk" firstAttribute="top" secondItem="LAG-N5-iQ3" secondAttribute="top" id="O3p-KC-nWY"/>
+                                            <constraint firstItem="RxL-qE-G5e" firstAttribute="leading" secondItem="LAG-N5-iQ3" secondAttribute="leading" id="OEl-Hw-KYt"/>
+                                            <constraint firstItem="aKo-zY-Gp8" firstAttribute="top" secondItem="RxL-qE-G5e" secondAttribute="bottom" constant="52" id="QrG-fq-pho"/>
+                                            <constraint firstItem="38q-hq-5aP" firstAttribute="top" secondItem="RxL-qE-G5e" secondAttribute="bottom" constant="8" id="cB5-s2-l95"/>
                                             <constraint firstItem="69S-Bx-TPQ" firstAttribute="leading" secondItem="GtB-mX-v1C" secondAttribute="trailing" constant="8" id="lUt-Jc-ZBW"/>
                                             <constraint firstItem="yhM-DQ-mT8" firstAttribute="leading" secondItem="LAG-N5-iQ3" secondAttribute="leading" id="o9F-YO-fep"/>
+                                            <constraint firstAttribute="trailing" secondItem="aKo-zY-Gp8" secondAttribute="trailing" id="pbX-lG-62C"/>
                                             <constraint firstAttribute="trailing" secondItem="LSZ-mG-8Wk" secondAttribute="trailing" id="ws8-ls-cF9"/>
+                                            <constraint firstItem="38q-hq-5aP" firstAttribute="leading" secondItem="LAG-N5-iQ3" secondAttribute="leading" id="zFa-OV-HU4"/>
                                             <constraint firstItem="GtB-mX-v1C" firstAttribute="leading" secondItem="yhM-DQ-mT8" secondAttribute="trailing" constant="8" id="zHl-Y5-s5c"/>
                                         </constraints>
                                     </customView>
                                     <customView translatesAutoresizingMaskIntoConstraints="NO" id="zPv-9H-oej">
-                                        <rect key="frame" x="15" y="256" width="232" height="72"/>
+                                        <rect key="frame" x="15" y="100" width="232" height="72"/>
                                         <subviews>
                                             <customView translatesAutoresizingMaskIntoConstraints="NO" id="cSB-tr-fTV">
                                                 <rect key="frame" x="0.0" y="32" width="232" height="40"/>
@@ -261,12 +298,21 @@
                                                     <constraint firstItem="tld-Xn-Y44" firstAttribute="centerY" secondItem="cSB-tr-fTV" secondAttribute="centerY" id="OfG-2j-6NZ"/>
                                                 </constraints>
                                             </customView>
+                                            <customView translatesAutoresizingMaskIntoConstraints="NO" id="dI8-s8-38t">
+                                                <rect key="frame" x="0.0" y="0.0" width="232" height="32"/>
+                                                <constraints>
+                                                    <constraint firstAttribute="height" constant="32" id="eRt-O6-xKS"/>
+                                                </constraints>
+                                            </customView>
                                         </subviews>
                                         <constraints>
                                             <constraint firstItem="cSB-tr-fTV" firstAttribute="leading" secondItem="zPv-9H-oej" secondAttribute="leading" id="1fW-fy-zhw"/>
+                                            <constraint firstAttribute="trailing" secondItem="dI8-s8-38t" secondAttribute="trailing" id="HRC-Pb-XSi"/>
                                             <constraint firstAttribute="width" constant="232" id="jXJ-Yv-jb7"/>
                                             <constraint firstItem="cSB-tr-fTV" firstAttribute="top" secondItem="zPv-9H-oej" secondAttribute="top" id="kdh-gg-lN0"/>
+                                            <constraint firstItem="dI8-s8-38t" firstAttribute="top" secondItem="cSB-tr-fTV" secondAttribute="bottom" id="mnj-2h-Eb3"/>
                                             <constraint firstAttribute="trailing" secondItem="cSB-tr-fTV" secondAttribute="trailing" id="r75-0k-5eE"/>
+                                            <constraint firstItem="dI8-s8-38t" firstAttribute="leading" secondItem="zPv-9H-oej" secondAttribute="leading" id="tPd-cW-Veg"/>
                                             <constraint firstAttribute="height" constant="72" id="utc-Yw-y97"/>
                                         </constraints>
                                     </customView>

+ 2 - 0
PDF Office/PDF Master/KMClass/KMPDFViewController/KMPDFViewManager.swift

@@ -22,6 +22,8 @@ class KMPDFViewManager: NSObject {
     
     var isPageEditMode: Bool = false  //页面编辑模式
     
+    var isPDFReadMode: Bool = false //阅读模式
+    
     //分割PDF相关
     var splitPDFFilePath: String?
     var splitPDFDocument: CPDFDocument?