diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 2be3976..46d6f98 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -32,7 +32,7 @@ CD8BFF1B23014867001E08DD /* TestGuardVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestGuardVC.swift; sourceTree = ""; }; CD8BFF1D230148DD001E08DD /* BaseListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseListVC.swift; sourceTree = ""; }; CD8BFF1F23014CB5001E08DD /* EmptyVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyVC.swift; sourceTree = ""; }; - CDA4E03820D3935B00CD2A0C /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + CDA4E03820D3935B00CD2A0C /* ProHUD (Xcode11之前的老项目).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ProHUD (Xcode11之前的老项目).app"; sourceTree = BUILT_PRODUCTS_DIR; }; CDA4E03B20D3935B00CD2A0C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; CDA4E03D20D3935B00CD2A0C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; CDA4E04020D3935B00CD2A0C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -83,7 +83,7 @@ CDA4E03920D3935B00CD2A0C /* Products */ = { isa = PBXGroup; children = ( - CDA4E03820D3935B00CD2A0C /* Example.app */, + CDA4E03820D3935B00CD2A0C /* ProHUD (Xcode11之前的老项目).app */, ); name = Products; sourceTree = ""; @@ -127,7 +127,7 @@ ); name = Example; productName = Example; - productReference = CDA4E03820D3935B00CD2A0C /* Example.app */; + productReference = CDA4E03820D3935B00CD2A0C /* ProHUD (Xcode11之前的老项目).app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ @@ -373,8 +373,8 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = 34W5TB5KD2; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -383,9 +383,9 @@ ); MARKETING_VERSION = 2.0; PRODUCT_BUNDLE_IDENTIFIER = com.xaoxuu.ProHUDExample; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_NAME = "ProHUD (Xcode11之前的老项目)"; PROVISIONING_PROFILE = "b32d51a3-c20b-408f-aebf-11d2ea3811cd"; - PROVISIONING_PROFILE_SPECIFIER = "com.xaoxuu.*"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Example/Example-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -399,8 +399,8 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = 34W5TB5KD2; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -409,9 +409,9 @@ ); MARKETING_VERSION = 2.0; PRODUCT_BUNDLE_IDENTIFIER = com.xaoxuu.ProHUDExample; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_NAME = "ProHUD (Xcode11之前的老项目)"; PROVISIONING_PROFILE = "b32d51a3-c20b-408f-aebf-11d2ea3811cd"; - PROVISIONING_PROFILE_SPECIFIER = "com.xaoxuu.*"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "Example/Example-Bridging-Header.h"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 1; diff --git a/Example/Example/Info.plist b/Example/Example/Info.plist index ed7fc0e..5fdbca5 100644 --- a/Example/Example/Info.plist +++ b/Example/Example/Info.plist @@ -5,7 +5,7 @@ CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleDisplayName - ProHUD + $(PRODUCT_NAME) CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier diff --git a/Example/Example/RootVC.swift b/Example/Example/RootVC.swift index 973b7b0..a775da1 100644 --- a/Example/Example/RootVC.swift +++ b/Example/Example/RootVC.swift @@ -18,6 +18,7 @@ class RootVC: UIViewController { let nav = UINavigationController(rootViewController: vc) addChild(nav) view.addSubview(nav.view) + nav.view.frame = view.bounds if #available(iOS 11.0, *) { nav.navigationBar.prefersLargeTitles = true } else { diff --git a/Example/Example/TestAlertVC.swift b/Example/Example/TestAlertVC.swift index 3f881d7..1807fbf 100644 --- a/Example/Example/TestAlertVC.swift +++ b/Example/Example/TestAlertVC.swift @@ -22,6 +22,7 @@ class TestAlertVC: BaseListVC { "场景:同步成功(写法1)", "场景:同步成功(写法2)", "场景:同步失败和重试", + "极端场景:短时间内调用了多次同一个弹窗", "极端场景:多个弹窗重叠"] } @@ -114,6 +115,50 @@ class TestAlertVC: BaseListVC { } loading() } else if row == 4 { + func loading(_ index: Int = 1) { + Alert.find("loading", last: { (a) in + Toast.find("loading-tip", last: { (t) in + t.update { (vm) in + vm.title = "此时又调用了一次相同的弹窗 x\(index)" + } + t.pulse() + }) { + Toast.push(title: "此时又调用了一次相同的弹窗 x\(index)", message: "页面应该是没有任何变化的") { (t) in + t.identifier = "loading-tip" + t.update { (vm) in + vm.scene = .default + + } + } + } + }) { + Alert.push() { (a) in + a.identifier = "loading" + a.update { (vm) in + vm.scene = .loading + vm.title = "正在加载" + } + a.rotate(direction: .counterclockwise) + } + } + } + loading(1) + DispatchQueue.main.asyncAfter(deadline: .now()+1) { + loading(2) + } + DispatchQueue.main.asyncAfter(deadline: .now()+2) { + loading(3) + } + DispatchQueue.main.asyncAfter(deadline: .now()+3) { + loading(4) + } + DispatchQueue.main.asyncAfter(deadline: .now()+3.5) { + loading(5) + } + DispatchQueue.main.asyncAfter(deadline: .now()+4) { + loading(6) + } + } else if row == 5 { func f(_ i: Int) { Alert.push() { (a) in a.rotate() diff --git a/Example/Example/TestGuardVC.swift b/Example/Example/TestGuardVC.swift index 709a48f..f63b604 100644 --- a/Example/Example/TestGuardVC.swift +++ b/Example/Example/TestGuardVC.swift @@ -114,11 +114,13 @@ class TestGuardVC: BaseListVC { let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) ac.addAction(ok) ac.addAction(cancel) + ac.popoverPresentationController?.sourceView = tableView.cellForRow(at: indexPath) self.present(ac, animated: true, completion: nil) } else if row == 4 { let vc = UIViewController() vc.view.backgroundColor = .white vc.title = "ceshi" + present(vc, animated: true, completion: nil) } diff --git a/Source/Alert/AlertController.swift b/Source/Alert/AlertController.swift index d3d51ef..8363aba 100644 --- a/Source/Alert/AlertController.swift +++ b/Source/Alert/AlertController.swift @@ -154,23 +154,11 @@ public extension Alert { /// 图片旋转效果 /// - Parameter flag: 是否开启 - func rotate(_ flag: Bool = true) { - if flag { - DispatchQueue.main.async { - let ani = CABasicAnimation(keyPath: "transform.rotation.z") - ani.toValue = -Double.pi * 2.0 - ani.duration = 3 - ani.repeatCount = 10000 - self.imageView?.layer.add(ani, forKey: "rotationAnimation") - } - } else { - imageView?.layer.removeAllAnimations() + func rotate(_ flag: Bool = true, direction: ProHUD.RotateDirection = .clockwise, speed: CFTimeInterval = 1) { + DispatchQueue.main.async { + self.imageView?.rotate(flag: flag, direction: direction, speed: speed) } } - - - - } diff --git a/Source/HUDView.swift b/Source/HUDView.swift index 8e8f588..3b0320b 100644 --- a/Source/HUDView.swift +++ b/Source/HUDView.swift @@ -26,7 +26,11 @@ public extension ProHUD { } } - + /// 旋转方向 + enum RotateDirection: Double { + case clockwise = 1 + case counterclockwise = -1 + } } internal extension Alert { @@ -146,4 +150,21 @@ internal extension UIView { animateForGuard(animations: animations, completion: nil) } + func rotate(flag: Bool, direction: ProHUD.RotateDirection, speed: CFTimeInterval) { + if flag == true { + if layer.animation(forKey: "rotationAnimation") == nil { + let ani = CABasicAnimation(keyPath: "transform.rotation.z") + ani.toValue = direction.rawValue * Double.pi * 2.0 + if speed > 0 { + ani.duration = 4 / speed + } + ani.repeatDuration = .infinity + layer.add(ani, forKey: "rotationAnimation") + } + } else { + layer.removeAnimation(forKey: "rotationAnimation") + } + } + + } diff --git a/Source/Toast/ToastController.swift b/Source/Toast/ToastController.swift index 4499e46..f01eaf7 100644 --- a/Source/Toast/ToastController.swift +++ b/Source/Toast/ToastController.swift @@ -183,17 +183,9 @@ public extension Toast { /// 图片旋转效果 /// - Parameter flag: 是否开启 - func rotate(_ flag: Bool = true) { - if flag { - DispatchQueue.main.async { - let ani = CABasicAnimation(keyPath: "transform.rotation.z") - ani.toValue = -Double.pi * 2.0 - ani.duration = 3 - ani.repeatCount = 10000 - self.imageView.layer.add(ani, forKey: "rotationAnimation") - } - } else { - imageView.layer.removeAllAnimations() + func rotate(_ flag: Bool = true, direction: ProHUD.RotateDirection = .clockwise, speed: CFTimeInterval = 1) { + DispatchQueue.main.async { + self.imageView.rotate(flag: flag, direction: direction, speed: speed) } }