图片旋转方向和速度

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>"; };
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>"; };
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>"; };
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>"; };
@ -83,7 +83,7 @@
CDA4E03920D3935B00CD2A0C /* Products */ = {
isa = PBXGroup;
children = (
CDA4E03820D3935B00CD2A0C /* Example.app */,
CDA4E03820D3935B00CD2A0C /* ProHUD (Xcode11之前的老项目).app */,
);
name = Products;
sourceTree = "<group>";
@ -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;

View File

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

View File

@ -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 {

View File

@ -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()

View File

@ -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)
}

View File

@ -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)
}
}
}

View File

@ -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")
}
}
}

View File

@ -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)
}
}