From 4a23ab048de15da7dd2fb47b3d0e3a7addd71f84 Mon Sep 17 00:00:00 2001 From: e-sung Date: Mon, 7 Jan 2019 20:28:23 +0900 Subject: [PATCH 1/2] feat: support swift 4.2 --- Classes/ZFRippleButton.swift | 12 ++++++------ .../ZFRippleButtonDemo.xcodeproj/project.pbxproj | 7 +++++-- .../ZFRippleButtonDemo/AppDelegate.swift | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Classes/ZFRippleButton.swift b/Classes/ZFRippleButton.swift index 33adcfa..e549646 100755 --- a/Classes/ZFRippleButton.swift +++ b/Classes/ZFRippleButton.swift @@ -108,14 +108,14 @@ open class ZFRippleButton: UIButton { touchCenterLocation = nil } - UIView.animate(withDuration: 0.1, delay: 0, options: UIViewAnimationOptions.allowUserInteraction, animations: { + UIView.animate(withDuration: 0.1, delay: 0, options: .allowUserInteraction, animations: { self.rippleBackgroundView.alpha = 1 }, completion: nil) rippleView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) - UIView.animate(withDuration: 0.7, delay: 0, options: [UIViewAnimationOptions.curveEaseOut, UIViewAnimationOptions.allowUserInteraction], + UIView.animate(withDuration: 0.7, delay: 0, options: [.curveEaseOut, .allowUserInteraction], animations: { self.rippleView.transform = CGAffineTransform.identity }, completion: nil) @@ -132,7 +132,7 @@ open class ZFRippleButton: UIButton { let groupAnim = CAAnimationGroup() groupAnim.duration = 0.7 - groupAnim.fillMode = kCAFillModeForwards + groupAnim.fillMode = .forwards groupAnim.isRemovedOnCompletion = false groupAnim.animations = [shadowAnim, opacityAnim] @@ -152,10 +152,10 @@ open class ZFRippleButton: UIButton { } fileprivate func animateToNormal() { - UIView.animate(withDuration: 0.1, delay: 0, options: UIViewAnimationOptions.allowUserInteraction, animations: { + UIView.animate(withDuration: 0.1, delay: 0, options: .allowUserInteraction, animations: { self.rippleBackgroundView.alpha = 1 }, completion: {(success: Bool) -> () in - UIView.animate(withDuration: self.touchUpAnimationTime, delay: 0, options: UIViewAnimationOptions.allowUserInteraction, animations: { + UIView.animate(withDuration: self.touchUpAnimationTime, delay: 0, options: .allowUserInteraction, animations: { self.rippleBackgroundView.alpha = 0 }, completion: nil) }) @@ -174,7 +174,7 @@ open class ZFRippleButton: UIButton { let groupAnim = CAAnimationGroup() groupAnim.duration = 0.7 - groupAnim.fillMode = kCAFillModeForwards + groupAnim.fillMode = .forwards groupAnim.isRemovedOnCompletion = false groupAnim.animations = [shadowAnim, opacityAnim] diff --git a/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo.xcodeproj/project.pbxproj b/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo.xcodeproj/project.pbxproj index a842232..2016ac8 100755 --- a/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo.xcodeproj/project.pbxproj +++ b/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo.xcodeproj/project.pbxproj @@ -174,6 +174,7 @@ TargetAttributes = { DC346CB6195F150E0099F81E = { CreatedOnToolsVersion = 6.0; + DevelopmentTeam = 7KT5X239S9; LastSwiftMigration = 0800; }; DC346CC8195F150E0099F81E = { @@ -352,11 +353,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 7KT5X239S9; INFOPLIST_FILE = ZFRippleButtonDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -364,11 +366,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 7KT5X239S9; INFOPLIST_FILE = ZFRippleButtonDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo/AppDelegate.swift b/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo/AppDelegate.swift index 7bd6405..c6777ec 100755 --- a/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo/AppDelegate.swift +++ b/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo/AppDelegate.swift @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } From 8b4b818633f54810f7e99902df394c3f39a35e75 Mon Sep 17 00:00:00 2001 From: e-sung Date: Mon, 7 Jan 2019 20:32:08 +0900 Subject: [PATCH 2/2] fix : memory leak on closures --- Classes/ZFRippleButton.swift | 26 +++++++++---------- .../project.pbxproj | 5 ++-- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Classes/ZFRippleButton.swift b/Classes/ZFRippleButton.swift index e549646..ac86d7a 100755 --- a/Classes/ZFRippleButton.swift +++ b/Classes/ZFRippleButton.swift @@ -108,16 +108,16 @@ open class ZFRippleButton: UIButton { touchCenterLocation = nil } - UIView.animate(withDuration: 0.1, delay: 0, options: .allowUserInteraction, animations: { - self.rippleBackgroundView.alpha = 1 + UIView.animate(withDuration: 0.1, delay: 0, options: .allowUserInteraction, animations: { [weak self] in + self?.rippleBackgroundView.alpha = 1 }, completion: nil) rippleView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) UIView.animate(withDuration: 0.7, delay: 0, options: [.curveEaseOut, .allowUserInteraction], - animations: { - self.rippleView.transform = CGAffineTransform.identity + animations: { [weak self] in + self?.rippleView.transform = CGAffineTransform.identity }, completion: nil) if shadowRippleEnable { @@ -152,25 +152,25 @@ open class ZFRippleButton: UIButton { } fileprivate func animateToNormal() { - UIView.animate(withDuration: 0.1, delay: 0, options: .allowUserInteraction, animations: { - self.rippleBackgroundView.alpha = 1 + UIView.animate(withDuration: 0.1, delay: 0, options: .allowUserInteraction, animations: { [weak self] in + self?.rippleBackgroundView.alpha = 1 }, completion: {(success: Bool) -> () in - UIView.animate(withDuration: self.touchUpAnimationTime, delay: 0, options: .allowUserInteraction, animations: { - self.rippleBackgroundView.alpha = 0 + UIView.animate(withDuration: self.touchUpAnimationTime, delay: 0, options: .allowUserInteraction, animations: { [weak self] in + self?.rippleBackgroundView.alpha = 0 }, completion: nil) }) UIView.animate(withDuration: 0.7, delay: 0, options: [.curveEaseOut, .beginFromCurrentState, .allowUserInteraction], - animations: { - self.rippleView.transform = CGAffineTransform.identity + animations: { [weak self, tempShadowRadius, tempShadowOpacity] in + self?.rippleView.transform = CGAffineTransform.identity let shadowAnim = CABasicAnimation(keyPath:"shadowRadius") - shadowAnim.toValue = self.tempShadowRadius + shadowAnim.toValue = tempShadowRadius let opacityAnim = CABasicAnimation(keyPath:"shadowOpacity") - opacityAnim.toValue = self.tempShadowOpacity + opacityAnim.toValue = tempShadowOpacity let groupAnim = CAAnimationGroup() groupAnim.duration = 0.7 @@ -178,7 +178,7 @@ open class ZFRippleButton: UIButton { groupAnim.isRemovedOnCompletion = false groupAnim.animations = [shadowAnim, opacityAnim] - self.layer.add(groupAnim, forKey:"shadowBack") + self?.layer.add(groupAnim, forKey:"shadowBack") }, completion: nil) } diff --git a/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo.xcodeproj/project.pbxproj b/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo.xcodeproj/project.pbxproj index 2016ac8..dbc68cb 100755 --- a/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo.xcodeproj/project.pbxproj +++ b/Demo/ZFRippleButtonDemo/ZFRippleButtonDemo.xcodeproj/project.pbxproj @@ -174,7 +174,6 @@ TargetAttributes = { DC346CB6195F150E0099F81E = { CreatedOnToolsVersion = 6.0; - DevelopmentTeam = 7KT5X239S9; LastSwiftMigration = 0800; }; DC346CC8195F150E0099F81E = { @@ -353,7 +352,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = 7KT5X239S9; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = ZFRippleButtonDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -366,7 +365,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = 7KT5X239S9; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = ZFRippleButtonDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";