소스 검색

【fix】mac端,个人中心点刷新按钮,刷新中的图标没有动效

tangchao 3 달 전
부모
커밋
909ff885b3

+ 3 - 49
PDF Office/PDF Master/Class/Account/Controller/AccountProfileController.swift

@@ -7,55 +7,6 @@
 
 import Cocoa
 
-class AccountLoadingView: NSView {
-    private lazy var contentBox_: NSBox = {
-        let view = NSBox()
-        view.boxType = .custom
-        view.titlePosition = .noTitle
-        view.contentViewMargins = .zero
-        view.borderWidth = 0
-        return view
-    }()
-    
-//    private lazy var titleLabel_: NSTextField = {
-//        let view = NSTextField(labelWithString: "")
-//        view.font = .systemFont(ofSize: 16)
-//        view.textColor = KMAppearance.titleColor()
-//        return view
-//    }()
-    
-    private lazy var iconIv_: NSImageView = {
-        let view = NSImageView()
-        view.image = NSImage(named: "KMImageNameAccountRefreshLoading")
-        return view
-    }()
-    
-    convenience init() {
-        self.init(frame: .init(x: 0, y: 0, width: 160, height: 118))
-        
-        self.initSubviews()
-    }
-    
-    override func awakeFromNib() {
-        super.awakeFromNib()
-        
-        self.initSubviews()
-    }
-    
-    func initSubviews() {
-        self.addSubview(self.contentBox_)
-        self.contentBox_.km_add_inset_constraint()
-        
-        self.contentBox_.contentView?.addSubview(self.iconIv_)
-        self.iconIv_.km_add_size_constraint(size: .init(width: 40, height: 40))
-        self.iconIv_.km_add_centerX_constraint()
-        self.iconIv_.km_add_centerY_constraint()
-        
-        self.contentBox_.fillColor = .black
-        self.contentBox_.cornerRadius = 10
-    }
-}
-
 class AccountProfileController: NSViewController {
     @IBOutlet weak var headerBox: NSBox!
     @IBOutlet weak var mainBox: NSBox!
@@ -326,9 +277,12 @@ class AccountProfileController: NSViewController {
         frame.origin.y = (viewFrame.size.height-frame.size.height)*0.5
         
         view.frame = frame
+        
+        view.startAnimation()
     }
     
     func hideLoading() {
+        self.loadingView_.stopAnimation()
         self.loadingView_.removeFromSuperview()
     }
     

+ 95 - 0
PDF Office/PDF Master/Class/Account/View/AccountLoadingView.swift

@@ -0,0 +1,95 @@
+//
+//  AccountLoadingView.swift
+//  PDF Reader Pro
+//
+//  Created by User-Tangchao on 2024/11/27.
+//
+
+import Cocoa
+
+class ConnectImageView: NSImageView {
+    lazy var contentLayer:CALayer = {
+        let imgLayer = CALayer()
+        imgLayer.frame = self.layer?.bounds ?? .zero
+        let image = NSImage(named: "KMImageNameAccountRefreshLoading")!
+        imgLayer.contents = image.layerContents(forContentsScale: self.layer!.contentsScale)
+        imgLayer.contentsScale = self.layer?.contentsScale ?? 0
+        return imgLayer
+    }()
+    
+    func startCircleAnimtion(clockwise:Bool = true) {
+        wantsLayer = true
+        contentLayer.frame = bounds
+        layer?.addSublayer(contentLayer)
+        //        print("layer archPoint:\(layer?.anchorPoint),new layer anchorPoint:\(newLayer.anchorPoint)")
+        // 注意⚠️,修改了anchorPoint会变更frame,无法实现预期在效果。在macOS上anchorPoint默认为(0,0),如果是新建一个Layer,则layer的anchorPoint默认为(0.5,0.5)
+        // 在拉伸视图时,默认layer的frame以及anchorPoint都发生了变化,造成动画不是预期的样子。
+        // 所以最终的解决方案是,单独新建一个子Layer,用来处理动画
+        let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
+        let from:CGFloat = CGFloat.pi * 2
+        let end:CGFloat = 0
+        rotateAnimation.fromValue = clockwise ? from : end
+        rotateAnimation.toValue = clockwise ? end : from
+        rotateAnimation.duration = 1.5
+        rotateAnimation.isAdditive = true
+        rotateAnimation.repeatDuration = CFTimeInterval.infinity
+        contentLayer.add(rotateAnimation, forKey: "rotateAnimation")
+    }
+    
+    func stopCircleAnimation() {
+        contentLayer.removeAnimation(forKey: "rotateAnimation")
+        contentLayer.removeFromSuperlayer()
+    }
+}
+
+class AccountLoadingView: NSView {
+    private lazy var contentBox_: NSBox = {
+        let view = NSBox()
+        view.boxType = .custom
+        view.titlePosition = .noTitle
+        view.contentViewMargins = .zero
+        view.borderWidth = 0
+        return view
+    }()
+    
+    private lazy var iconIv_: ConnectImageView = {
+        let view = ConnectImageView()
+//        view.image = NSImage(named: "KMImageNameAccountRefreshLoading")
+        return view
+    }()
+    
+    convenience init() {
+        self.init(frame: .init(x: 0, y: 0, width: 160, height: 118))
+        
+        self.initSubviews()
+    }
+    
+    override func awakeFromNib() {
+        super.awakeFromNib()
+        
+        self.initSubviews()
+    }
+    
+    func initSubviews() {
+        self.addSubview(self.contentBox_)
+        self.contentBox_.km_add_inset_constraint()
+        
+        self.contentBox_.contentView?.addSubview(self.iconIv_)
+        self.iconIv_.km_add_size_constraint(size: .init(width: 40, height: 40))
+        self.iconIv_.km_add_centerX_constraint()
+        self.iconIv_.km_add_centerY_constraint()
+        
+        self.contentBox_.fillColor = .black
+        self.contentBox_.cornerRadius = 10
+    }
+    
+    func startAnimation() {
+        DispatchQueue.main.async {
+            self.iconIv_.startCircleAnimtion()
+        }
+    }
+    
+    func stopAnimation() {
+        self.iconIv_.stopCircleAnimation()
+    }
+}

+ 8 - 0
PDF Office/PDF Reader Pro.xcodeproj/project.pbxproj

@@ -160,6 +160,9 @@
 		65B95F8E2CD2936D000E8A01 /* AccountLogoutWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65B95F8A2CD2936D000E8A01 /* AccountLogoutWindowController.xib */; };
 		65B95F8F2CD2936D000E8A01 /* AccountLogoutWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65B95F8A2CD2936D000E8A01 /* AccountLogoutWindowController.xib */; };
 		65B95F902CD2936D000E8A01 /* AccountLogoutWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 65B95F8A2CD2936D000E8A01 /* AccountLogoutWindowController.xib */; };
+		65BC23182CF6C92B0055EFC7 /* AccountLoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BC23172CF6C92B0055EFC7 /* AccountLoadingView.swift */; };
+		65BC23192CF6C92B0055EFC7 /* AccountLoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BC23172CF6C92B0055EFC7 /* AccountLoadingView.swift */; };
+		65BC231A2CF6C92B0055EFC7 /* AccountLoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BC23172CF6C92B0055EFC7 /* AccountLoadingView.swift */; };
 		65BCA0122CD3426C00F4FC11 /* AccountUnsubscribeWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BCA0102CD3426C00F4FC11 /* AccountUnsubscribeWindowController.swift */; };
 		65BCA0132CD3426C00F4FC11 /* AccountUnsubscribeWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BCA0102CD3426C00F4FC11 /* AccountUnsubscribeWindowController.swift */; };
 		65BCA0142CD3426C00F4FC11 /* AccountUnsubscribeWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BCA0102CD3426C00F4FC11 /* AccountUnsubscribeWindowController.swift */; };
@@ -5808,6 +5811,7 @@
 		65B95F822CD21997000E8A01 /* AccountMoreBenefitsController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccountMoreBenefitsController.xib; sourceTree = "<group>"; };
 		65B95F892CD2936D000E8A01 /* AccountLogoutWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountLogoutWindowController.swift; sourceTree = "<group>"; };
 		65B95F8A2CD2936D000E8A01 /* AccountLogoutWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccountLogoutWindowController.xib; sourceTree = "<group>"; };
+		65BC23172CF6C92B0055EFC7 /* AccountLoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountLoadingView.swift; sourceTree = "<group>"; };
 		65BCA0102CD3426C00F4FC11 /* AccountUnsubscribeWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountUnsubscribeWindowController.swift; sourceTree = "<group>"; };
 		65BCA0112CD3426C00F4FC11 /* AccountUnsubscribeWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccountUnsubscribeWindowController.xib; sourceTree = "<group>"; };
 		65BCA0182CD353B200F4FC11 /* AccountPwdChangedWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountPwdChangedWindowController.swift; sourceTree = "<group>"; };
@@ -8256,6 +8260,7 @@
 				6582FA0F2CCF7F0B001D6D1E /* AccountInputView.swift */,
 				65B95F712CD1E3E3000E8A01 /* AccountBenefitCellView.swift */,
 				65B95F7D2CD201BC000E8A01 /* AccountRightCellView.swift */,
+				65BC23172CF6C92B0055EFC7 /* AccountLoadingView.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -18011,6 +18016,7 @@
 				BB403BAA2B15CA6E00B3106D /* KMBatchConvertOperation.swift in Sources */,
 				9FB220EC2B185B3100A5B208 /* KMButtomCell.swift in Sources */,
 				BBFA1CCD2B609E890053AD4A /* KMScreenShotMaskWindowController.swift in Sources */,
+				65BC23182CF6C92B0055EFC7 /* AccountLoadingView.swift in Sources */,
 				9F1FE4C929406E4700E952CA /* CTTabContents.m in Sources */,
 				9FCFEC882AD0EF9900EAD2CB /* KMPopMenuButton.swift in Sources */,
 				9F39B9442A661ED500930ACA /* KMHomeScrollView.swift in Sources */,
@@ -18971,6 +18977,7 @@
 				AD3AAD642B0DA3F600DE5FE7 /* KMCompareTextHeaderView.swift in Sources */,
 				ADE86AC92B034CB200414DFA /* KMAddBackgroundView.swift in Sources */,
 				BB67EE212B54FFEF00573BF0 /* ASIDataDecompressor.m in Sources */,
+				65BC23192CF6C92B0055EFC7 /* AccountLoadingView.swift in Sources */,
 				BB88E45929404752002B3655 /* KMPDFConvert.swift in Sources */,
 				9F080B15298CFDB300FC27DA /* KMTextImageButtonVC.swift in Sources */,
 				BB27BF3D2B33E85200A0BAAE /* CPDFView+KMExtension.swift in Sources */,
@@ -19930,6 +19937,7 @@
 				ADEC7A80299397F8009A8256 /* NSFont+SFProText.swift in Sources */,
 				9F72D2052994A3B800DCACF1 /* KMDesignToken+Notification.swift in Sources */,
 				ADC63E392A49813E00854E02 /* KMSubscribeSuccessWindowController.swift in Sources */,
+				65BC231A2CF6C92B0055EFC7 /* AccountLoadingView.swift in Sources */,
 				BBC348042955403D008D2CD1 /* KMWatermarkFilePropertyInfoController.swift in Sources */,
 				AD9527DD2952EE700039D2BC /* KMPrintPage_C.swift in Sources */,
 				9FDD0FB9295D5230000C4DAD /* KMToolbarController.swift in Sources */,