图片旋转方向和速度

This commit is contained in:
xaoxuu 2020-06-16 16:50:53 +08:00
parent 80a17dc2b8
commit 7a00253f3a
8 changed files with 88 additions and 39 deletions

View File

@ -32,7 +32,7 @@
CD8BFF1B23014867001E08DD /* TestGuardVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestGuardVC.swift; sourceTree = "<group>"; }; CD8BFF1B23014867001E08DD /* TestGuardVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestGuardVC.swift; sourceTree = "<group>"; };
CD8BFF1D230148DD001E08DD /* BaseListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseListVC.swift; sourceTree = "<group>"; }; CD8BFF1D230148DD001E08DD /* BaseListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseListVC.swift; sourceTree = "<group>"; };
CD8BFF1F23014CB5001E08DD /* EmptyVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyVC.swift; sourceTree = "<group>"; }; CD8BFF1F23014CB5001E08DD /* EmptyVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyVC.swift; sourceTree = "<group>"; };
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 = "<group>"; }; CDA4E03B20D3935B00CD2A0C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
CDA4E03D20D3935B00CD2A0C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; }; CDA4E03D20D3935B00CD2A0C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
CDA4E04020D3935B00CD2A0C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; }; CDA4E04020D3935B00CD2A0C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
@ -83,7 +83,7 @@
CDA4E03920D3935B00CD2A0C /* Products */ = { CDA4E03920D3935B00CD2A0C /* Products */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
CDA4E03820D3935B00CD2A0C /* Example.app */, CDA4E03820D3935B00CD2A0C /* ProHUD (Xcode11之前的老项目).app */,
); );
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
@ -127,7 +127,7 @@
); );
name = Example; name = Example;
productName = Example; productName = Example;
productReference = CDA4E03820D3935B00CD2A0C /* Example.app */; productReference = CDA4E03820D3935B00CD2A0C /* ProHUD (Xcode11之前的老项目).app */;
productType = "com.apple.product-type.application"; productType = "com.apple.product-type.application";
}; };
/* End PBXNativeTarget section */ /* End PBXNativeTarget section */
@ -373,8 +373,8 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 34W5TB5KD2; DEVELOPMENT_TEAM = 34W5TB5KD2;
INFOPLIST_FILE = Example/Info.plist; INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
@ -383,9 +383,9 @@
); );
MARKETING_VERSION = 2.0; MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.xaoxuu.ProHUDExample; PRODUCT_BUNDLE_IDENTIFIER = com.xaoxuu.ProHUDExample;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "ProHUD (Xcode11之前的老项目)";
PROVISIONING_PROFILE = "b32d51a3-c20b-408f-aebf-11d2ea3811cd"; 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_OBJC_BRIDGING_HEADER = "Example/Example-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
@ -399,8 +399,8 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 34W5TB5KD2; DEVELOPMENT_TEAM = 34W5TB5KD2;
INFOPLIST_FILE = Example/Info.plist; INFOPLIST_FILE = Example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
@ -409,9 +409,9 @@
); );
MARKETING_VERSION = 2.0; MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.xaoxuu.ProHUDExample; PRODUCT_BUNDLE_IDENTIFIER = com.xaoxuu.ProHUDExample;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "ProHUD (Xcode11之前的老项目)";
PROVISIONING_PROFILE = "b32d51a3-c20b-408f-aebf-11d2ea3811cd"; 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_OBJC_BRIDGING_HEADER = "Example/Example-Bridging-Header.h";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 1; TARGETED_DEVICE_FAMILY = 1;

View File

@ -5,7 +5,7 @@
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string> <string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
<string>ProHUD</string> <string>$(PRODUCT_NAME)</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string> <string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>

View File

@ -18,6 +18,7 @@ class RootVC: UIViewController {
let nav = UINavigationController(rootViewController: vc) let nav = UINavigationController(rootViewController: vc)
addChild(nav) addChild(nav)
view.addSubview(nav.view) view.addSubview(nav.view)
nav.view.frame = view.bounds
if #available(iOS 11.0, *) { if #available(iOS 11.0, *) {
nav.navigationBar.prefersLargeTitles = true nav.navigationBar.prefersLargeTitles = true
} else { } else {

View File

@ -22,6 +22,7 @@ class TestAlertVC: BaseListVC {
"场景同步成功写法1", "场景同步成功写法1",
"场景同步成功写法2", "场景同步成功写法2",
"场景:同步失败和重试", "场景:同步失败和重试",
"极端场景:短时间内调用了多次同一个弹窗",
"极端场景:多个弹窗重叠"] "极端场景:多个弹窗重叠"]
} }
@ -114,6 +115,50 @@ class TestAlertVC: BaseListVC {
} }
loading() loading()
} else if row == 4 { } 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) { func f(_ i: Int) {
Alert.push() { (a) in Alert.push() { (a) in
a.rotate() a.rotate()

View File

@ -114,11 +114,13 @@ class TestGuardVC: BaseListVC {
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
ac.addAction(ok) ac.addAction(ok)
ac.addAction(cancel) ac.addAction(cancel)
ac.popoverPresentationController?.sourceView = tableView.cellForRow(at: indexPath)
self.present(ac, animated: true, completion: nil) self.present(ac, animated: true, completion: nil)
} else if row == 4 { } else if row == 4 {
let vc = UIViewController() let vc = UIViewController()
vc.view.backgroundColor = .white vc.view.backgroundColor = .white
vc.title = "ceshi" vc.title = "ceshi"
present(vc, animated: true, completion: nil) present(vc, animated: true, completion: nil)
} }

View File

@ -154,23 +154,11 @@ public extension Alert {
/// ///
/// - Parameter flag: /// - Parameter flag:
func rotate(_ flag: Bool = true) { func rotate(_ flag: Bool = true, direction: ProHUD.RotateDirection = .clockwise, speed: CFTimeInterval = 1) {
if flag {
DispatchQueue.main.async { DispatchQueue.main.async {
let ani = CABasicAnimation(keyPath: "transform.rotation.z") self.imageView?.rotate(flag: flag, direction: direction, speed: speed)
ani.toValue = -Double.pi * 2.0
ani.duration = 3
ani.repeatCount = 10000
self.imageView?.layer.add(ani, forKey: "rotationAnimation")
}
} else {
imageView?.layer.removeAllAnimations()
} }
} }
} }

View File

@ -26,7 +26,11 @@ public extension ProHUD {
} }
} }
///
enum RotateDirection: Double {
case clockwise = 1
case counterclockwise = -1
}
} }
internal extension Alert { internal extension Alert {
@ -146,4 +150,21 @@ internal extension UIView {
animateForGuard(animations: animations, completion: nil) 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")
}
}
} }

View File

@ -183,17 +183,9 @@ public extension Toast {
/// ///
/// - Parameter flag: /// - Parameter flag:
func rotate(_ flag: Bool = true) { func rotate(_ flag: Bool = true, direction: ProHUD.RotateDirection = .clockwise, speed: CFTimeInterval = 1) {
if flag {
DispatchQueue.main.async { DispatchQueue.main.async {
let ani = CABasicAnimation(keyPath: "transform.rotation.z") self.imageView.rotate(flag: flag, direction: direction, speed: speed)
ani.toValue = -Double.pi * 2.0
ani.duration = 3
ani.repeatCount = 10000
self.imageView.layer.add(ani, forKey: "rotationAnimation")
}
} else {
imageView.layer.removeAllAnimations()
} }
} }