From 380f6272e0b0262d475c6bc58755744d0aa3237b Mon Sep 17 00:00:00 2001 From: paubins Date: Fri, 9 Jun 2017 11:05:03 -0700 Subject: [PATCH 1/2] Converted to Swift 3 --- .../project.pbxproj | 3 + .../AnimatablePlayButton.swift | 213 +++++++++--------- .../project.pbxproj | 49 +++- .../AppDelegate.swift | 12 +- .../ViewController.swift | 14 +- 5 files changed, 174 insertions(+), 117 deletions(-) diff --git a/AnimatablePlayButton.xcodeproj/project.pbxproj b/AnimatablePlayButton.xcodeproj/project.pbxproj index 5fccc24..97d9ba4 100644 --- a/AnimatablePlayButton.xcodeproj/project.pbxproj +++ b/AnimatablePlayButton.xcodeproj/project.pbxproj @@ -98,6 +98,7 @@ TargetAttributes = { 892EE43D1C1EE5FC00A9BE36 = { CreatedOnToolsVersion = 7.1; + LastSwiftMigration = 0830; }; }; }; @@ -244,6 +245,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -261,6 +263,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.keishi.suzuki.AnimatablePlayButton; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/AnimatablePlayButton/AnimatablePlayButton.swift b/AnimatablePlayButton/AnimatablePlayButton.swift index a9ff47b..0709a3a 100644 --- a/AnimatablePlayButton/AnimatablePlayButton.swift +++ b/AnimatablePlayButton/AnimatablePlayButton.swift @@ -1,4 +1,4 @@ -// + // AnimatablePlayButton.swift // AnimatablePlayButton // @@ -8,41 +8,41 @@ import UIKit -public class AnimatablePlayButton: UIButton { +open class AnimatablePlayButton: UIButton { - public var color: UIColor! = .whiteColor() { + open var color: UIColor! = .white { didSet { - pauseLeft.strokeColor = color.CGColor - pauseLeftMover.strokeColor = color.CGColor - pauseRight.strokeColor = color.CGColor - pauseRightMover.strokeColor = color.CGColor + pauseLeft.strokeColor = color.cgColor + pauseLeftMover.strokeColor = color.cgColor + pauseRight.strokeColor = color.cgColor + pauseRightMover.strokeColor = color.cgColor } } - public var bgColor: UIColor! = .blackColor() { + open var bgColor: UIColor! = .black { didSet { backgroundColor = bgColor - playTop.strokeColor = bgColor.CGColor - playBottom.strokeColor = bgColor.CGColor + playTop.strokeColor = bgColor.cgColor + playBottom.strokeColor = bgColor.cgColor } } - private let pauseLeftSelectAnimation = CAKeyframeAnimation(keyPath: "transform") - private let pauseRightSelectAnimation = CAKeyframeAnimation(keyPath: "transform") - private let playTopSelectAnimation = CAKeyframeAnimation(keyPath: "transform") - private let playBottomSelectAnimation = CAKeyframeAnimation(keyPath: "transform") - private let pauseLeftDeSelectAnimation = CAKeyframeAnimation(keyPath: "transform") - private let pauseRightDeSelectAnimation = CAKeyframeAnimation(keyPath: "transform") - private let playTopDeSelectAnimation = CAKeyframeAnimation(keyPath: "transform") - private let playBottomDeSelectAnimation = CAKeyframeAnimation(keyPath: "transform") + fileprivate let pauseLeftSelectAnimation = CAKeyframeAnimation(keyPath: "transform") + fileprivate let pauseRightSelectAnimation = CAKeyframeAnimation(keyPath: "transform") + fileprivate let playTopSelectAnimation = CAKeyframeAnimation(keyPath: "transform") + fileprivate let playBottomSelectAnimation = CAKeyframeAnimation(keyPath: "transform") + fileprivate let pauseLeftDeSelectAnimation = CAKeyframeAnimation(keyPath: "transform") + fileprivate let pauseRightDeSelectAnimation = CAKeyframeAnimation(keyPath: "transform") + fileprivate let playTopDeSelectAnimation = CAKeyframeAnimation(keyPath: "transform") + fileprivate let playBottomDeSelectAnimation = CAKeyframeAnimation(keyPath: "transform") - private var pauseLeft: CAShapeLayer = CAShapeLayer() - private var pauseLeftMover: CAShapeLayer = CAShapeLayer() - private var pauseRight: CAShapeLayer = CAShapeLayer() - private var pauseRightMover: CAShapeLayer = CAShapeLayer() - private var playTop: CAShapeLayer = CAShapeLayer() - private var playBottom: CAShapeLayer = CAShapeLayer() + fileprivate var pauseLeft: CAShapeLayer = CAShapeLayer() + fileprivate var pauseLeftMover: CAShapeLayer = CAShapeLayer() + fileprivate var pauseRight: CAShapeLayer = CAShapeLayer() + fileprivate var pauseRightMover: CAShapeLayer = CAShapeLayer() + fileprivate var playTop: CAShapeLayer = CAShapeLayer() + fileprivate var playBottom: CAShapeLayer = CAShapeLayer() - public override func awakeFromNib() { + open override func awakeFromNib() { super.awakeFromNib() setup() createLayers(frame) @@ -61,21 +61,21 @@ public class AnimatablePlayButton: UIButton { } convenience public init(origin: CGPoint, lengthOfSize: CGFloat){ - self.init(frame: CGRectMake(origin.x, origin.y, lengthOfSize, lengthOfSize)) + self.init(frame: CGRect(x: origin.x, y: origin.y, width: lengthOfSize, height: lengthOfSize)) } convenience public init(lengthOfSize: CGFloat){ - self.init(frame: CGRectMake(0, 0, lengthOfSize, lengthOfSize)) + self.init(frame: CGRect(x: 0, y: 0, width: lengthOfSize, height: lengthOfSize)) } // MARK: - private - private func setup(){ + fileprivate func setup(){ clipsToBounds = true - bgColor = .blackColor() - color = .whiteColor() + bgColor = .black + color = .white } - private func createLayers(frame: CGRect) { + fileprivate func createLayers(_ frame: CGRect) { let pauseLineWidth:CGFloat = bounds.width/5 let pauseLine:CGFloat = pauseLineWidth * 2 @@ -83,9 +83,11 @@ public class AnimatablePlayButton: UIButton { let pauseHeight = bounds.height-(pausePadding*2) let pausePath: CGPath = { - let path = CGPathCreateMutable() - CGPathMoveToPoint(path, nil, 0, 0) - CGPathAddLineToPoint(path, nil, 0, pauseHeight) + let path = CGMutablePath() + + path.move(to: CGPoint(x: 0.0, y: 0.0), transform: .identity) + path.addLine(to: CGPoint(x: 0.0, y: pauseHeight), transform: .identity) + return path }() @@ -94,107 +96,112 @@ public class AnimatablePlayButton: UIButton { pauseRight.path = pausePath pauseRightMover.path = pausePath playTop.path = { - let path = CGPathCreateMutable() - CGPathMoveToPoint(path, nil, 0, 0) - CGPathAddLineToPoint(path, nil, bounds.width, bounds.height / 2) + let path = CGMutablePath() + + path.move(to: CGPoint(x: 0.0, y: 0.0), transform: .identity) + path.addLine(to: CGPoint(x: bounds.width, y: bounds.height / 2), transform: .identity) + return path }() + playBottom.path = { - let path = CGPathCreateMutable() - CGPathMoveToPoint(path, nil, 0, bounds.height) - CGPathAddLineToPoint(path, nil, bounds.width, bounds.height / 2) + let path = CGMutablePath() + + path.move(to: CGPoint(x: 0.0, y: bounds.height), transform: .identity) + path.addLine(to: CGPoint(x: bounds.width, y: bounds.height / 2), transform: .identity) + return path }() - pauseLeft.frame = CGRectMake((bounds.width/5)*1, pausePadding, pauseLine, pauseHeight) + pauseLeft.frame = CGRect(x: (bounds.width/5)*1, y: pausePadding, width: pauseLine, height: pauseHeight) pauseLeft.lineWidth = pauseLine pauseLeft.masksToBounds = true layer.addSublayer(pauseLeft) - pauseLeftMover.frame = CGRectMake((bounds.width/5)*1, pausePadding, pauseLine * 1.25, pauseHeight) + pauseLeftMover.frame = CGRect(x: (bounds.width/5)*1, y: pausePadding, width: pauseLine * 1.25, height: pauseHeight) pauseLeftMover.lineWidth = pauseLine * 1.25 pauseLeftMover.masksToBounds = true layer.addSublayer(pauseLeftMover) - pauseRight.frame = CGRectMake((bounds.width/5)*3, pausePadding, pauseLine, pauseHeight) + pauseRight.frame = CGRect(x: (bounds.width/5)*3, y: pausePadding, width: pauseLine, height: pauseHeight) pauseRight.lineWidth = pauseLine pauseRight.masksToBounds = true layer.addSublayer(pauseRight) - pauseRightMover.frame = CGRectMake((bounds.width/5)*3, pausePadding, pauseLine * 1.25, pauseHeight) + pauseRightMover.frame = CGRect(x: (bounds.width/5)*3, y: pausePadding, width: pauseLine * 1.25, height: pauseHeight) pauseRightMover.lineWidth = pauseLine * 1.25 pauseRightMover.masksToBounds = true layer.addSublayer(pauseRightMover) - playTop.frame = CGRectMake(0, -bounds.height, bounds.width-1, bounds.height) + playTop.frame = CGRect(x: 0, y: -bounds.height, width: bounds.width-1, height: bounds.height) playTop.lineWidth = pauseLineWidth * 3 playTop.masksToBounds = true layer.addSublayer(playTop) - playBottom.frame = CGRectMake(0, bounds.height, bounds.width-1, bounds.height) + playBottom.frame = CGRect(x: 0, y: bounds.height, width: bounds.width-1, height: bounds.height) playBottom.lineWidth = pauseLineWidth * 3 playBottom.masksToBounds = true layer.addSublayer(playBottom) // SELECT pauseLeftSelectAnimation.values = [ - NSValue(CATransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.51, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.51, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.51, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.51, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.51, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.51, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.51, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.51, 0, 0)), ] pauseRightSelectAnimation.values = [ - NSValue(CATransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.51, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.51, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.51, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.51, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.51, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.51, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.51, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.51, 0, 0)), ] playTopSelectAnimation.values = [ - NSValue(CATransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.3, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.76, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.76, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.76, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.76, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.3, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.76, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.76, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.76, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.76, 0)), ] playBottomSelectAnimation.values = [ - NSValue(CATransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.3, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.76, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.76, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.76, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.76, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.3, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.76, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.76, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.76, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.76, 0)), ] // DESELECT pauseLeftDeSelectAnimation.values = [ - NSValue(CATransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.5, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.2, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.1, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.0, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.0, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.5, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.2, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.1, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.0, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(pauseLineWidth * 0.0, 0, 0)), ] pauseRightDeSelectAnimation.values = [ - NSValue(CATransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.5, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.2, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.1, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.0, 0, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.0, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.5, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.2, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.1, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.0, 0, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(-pauseLineWidth * 0.0, 0, 0)), ] playTopDeSelectAnimation.values = [ - NSValue(CATransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.76, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.4, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.3, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.2, 0)), - NSValue(CATransform3D: CATransform3DIdentity), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.76, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.4, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.3, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, bounds.height * 0.2, 0)), + NSValue(caTransform3D: CATransform3DIdentity), ] playBottomDeSelectAnimation.values = [ - NSValue(CATransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.76, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.4, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.3, 0)), - NSValue(CATransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.2, 0)), - NSValue(CATransform3D: CATransform3DIdentity), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.76, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.4, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.3, 0)), + NSValue(caTransform3D: CATransform3DMakeTranslation(0, -bounds.height * 0.2, 0)), + NSValue(caTransform3D: CATransform3DIdentity), ] setPauseProperty(pauseLeftSelectAnimation) @@ -203,23 +210,23 @@ public class AnimatablePlayButton: UIButton { setCommonProperty(playBottomSelectAnimation) } - private func setPauseProperty(animation: CAKeyframeAnimation) { + fileprivate func setPauseProperty(_ animation: CAKeyframeAnimation) { animation.duration = 0.4 animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn) - animation.removedOnCompletion = false + animation.isRemovedOnCompletion = false animation.fillMode = kCAFillModeForwards } - private func setCommonProperty(animation: CAKeyframeAnimation) { + fileprivate func setCommonProperty(_ animation: CAKeyframeAnimation) { animation.duration = 0.4 animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) - animation.removedOnCompletion = false + animation.isRemovedOnCompletion = false animation.fillMode = kCAFillModeForwards } // MARK: - public - public func select() { - selected = true + open func select() { + isSelected = true pauseLeftMover.removeAllAnimations() pauseRightMover.removeAllAnimations() @@ -228,16 +235,16 @@ public class AnimatablePlayButton: UIButton { CATransaction.begin() - pauseLeftMover.addAnimation(pauseLeftSelectAnimation, forKey: "transform") - pauseRightMover.addAnimation(pauseRightSelectAnimation, forKey: "transform") - playTop.addAnimation(playTopSelectAnimation, forKey: "transform") - playBottom.addAnimation(playBottomSelectAnimation, forKey: "transform") + pauseLeftMover.add(pauseLeftSelectAnimation, forKey: "transform") + pauseRightMover.add(pauseRightSelectAnimation, forKey: "transform") + playTop.add(playTopSelectAnimation, forKey: "transform") + playBottom.add(playBottomSelectAnimation, forKey: "transform") CATransaction.commit() } - public func deselect() { - selected = false + open func deselect() { + isSelected = false pauseLeftMover.removeAllAnimations() pauseRightMover.removeAllAnimations() @@ -246,11 +253,11 @@ public class AnimatablePlayButton: UIButton { CATransaction.begin() - pauseLeftMover.addAnimation(pauseLeftDeSelectAnimation, forKey: "transform") - pauseRightMover.addAnimation(pauseRightDeSelectAnimation, forKey: "transform") - playTop.addAnimation(playTopDeSelectAnimation, forKey: "transform") - playBottom.addAnimation(playBottomDeSelectAnimation, forKey: "transform") + pauseLeftMover.add(pauseLeftDeSelectAnimation, forKey: "transform") + pauseRightMover.add(pauseRightDeSelectAnimation, forKey: "transform") + playTop.add(playTopDeSelectAnimation, forKey: "transform") + playBottom.add(playBottomDeSelectAnimation, forKey: "transform") CATransaction.commit() } -} \ No newline at end of file +} diff --git a/AnimatablePlayButtonExample/AnimatablePlayButtonExample.xcodeproj/project.pbxproj b/AnimatablePlayButtonExample/AnimatablePlayButtonExample.xcodeproj/project.pbxproj index 2c997ca..3d8c4fb 100644 --- a/AnimatablePlayButtonExample/AnimatablePlayButtonExample.xcodeproj/project.pbxproj +++ b/AnimatablePlayButtonExample/AnimatablePlayButtonExample.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 5F3B37871EEB1AA60019ED66 /* AnimatablePlayButton.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 892EE46E1C1EE67700A9BE36 /* AnimatablePlayButton.framework */; }; + 5F3B37881EEB1AA60019ED66 /* AnimatablePlayButton.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 892EE46E1C1EE67700A9BE36 /* AnimatablePlayButton.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 892EE4581C1EE64700A9BE36 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892EE4571C1EE64700A9BE36 /* AppDelegate.swift */; }; 892EE45A1C1EE64700A9BE36 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 892EE4591C1EE64700A9BE36 /* ViewController.swift */; }; 892EE45D1C1EE64700A9BE36 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 892EE45B1C1EE64700A9BE36 /* Main.storyboard */; }; @@ -16,6 +18,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 5F3B37891EEB1AA60019ED66 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 892EE4691C1EE67700A9BE36 /* AnimatablePlayButton.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 892EE43D1C1EE5FC00A9BE36; + remoteInfo = AnimatablePlayButton; + }; 892EE46D1C1EE67700A9BE36 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 892EE4691C1EE67700A9BE36 /* AnimatablePlayButton.xcodeproj */; @@ -25,6 +34,20 @@ }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + 5F3B378B1EEB1AA60019ED66 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 5F3B37881EEB1AA60019ED66 /* AnimatablePlayButton.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 892EE4541C1EE64700A9BE36 /* AnimatablePlayButtonExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AnimatablePlayButtonExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 892EE4571C1EE64700A9BE36 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -41,6 +64,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 5F3B37871EEB1AA60019ED66 /* AnimatablePlayButton.framework in Frameworks */, 893180731C243BA7005BE57F /* AnimatablePlayButton.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -96,10 +120,12 @@ 892EE4501C1EE64700A9BE36 /* Sources */, 892EE4511C1EE64700A9BE36 /* Frameworks */, 892EE4521C1EE64700A9BE36 /* Resources */, + 5F3B378B1EEB1AA60019ED66 /* Embed Frameworks */, ); buildRules = ( ); dependencies = ( + 5F3B378A1EEB1AA60019ED66 /* PBXTargetDependency */, ); name = AnimatablePlayButtonExample; productName = AnimatablePlayButtonExample; @@ -113,11 +139,13 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0830; ORGANIZATIONNAME = suzuki_keishi; TargetAttributes = { 892EE4531C1EE64700A9BE36 = { CreatedOnToolsVersion = 7.1; + DevelopmentTeam = 3XSPEUHQ6Y; + LastSwiftMigration = 0830; }; }; }; @@ -180,6 +208,14 @@ }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 5F3B378A1EEB1AA60019ED66 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = AnimatablePlayButton; + targetProxy = 5F3B37891EEB1AA60019ED66 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ 892EE45B1C1EE64700A9BE36 /* Main.storyboard */ = { isa = PBXVariantGroup; @@ -213,8 +249,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -258,8 +296,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -278,6 +318,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.1; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -286,22 +327,28 @@ 892EE4671C1EE64700A9BE36 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 3XSPEUHQ6Y; INFOPLIST_FILE = AnimatablePlayButtonExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.keishi.suzuki.AnimatablePlayButtonExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; 892EE4681C1EE64700A9BE36 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 3XSPEUHQ6Y; INFOPLIST_FILE = AnimatablePlayButtonExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.keishi.suzuki.AnimatablePlayButtonExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/AnimatablePlayButtonExample/AnimatablePlayButtonExample/AppDelegate.swift b/AnimatablePlayButtonExample/AnimatablePlayButtonExample/AppDelegate.swift index dd99900..d0b7355 100644 --- a/AnimatablePlayButtonExample/AnimatablePlayButtonExample/AppDelegate.swift +++ b/AnimatablePlayButtonExample/AnimatablePlayButtonExample/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/AnimatablePlayButtonExample/AnimatablePlayButtonExample/ViewController.swift b/AnimatablePlayButtonExample/AnimatablePlayButtonExample/ViewController.swift index 20f199d..b450064 100644 --- a/AnimatablePlayButtonExample/AnimatablePlayButtonExample/ViewController.swift +++ b/AnimatablePlayButtonExample/AnimatablePlayButtonExample/ViewController.swift @@ -14,19 +14,19 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = .blackColor() + view.backgroundColor = .black let button = AnimatablePlayButton(lengthOfSize: 120) - button.center = CGPointMake(CGRectGetMidX(view.frame), CGRectGetMidY(view.frame)) - button.bgColor = .blackColor() - button.color = .whiteColor() - button.addTarget(self, action: Selector("tapped:"), forControlEvents: UIControlEvents.TouchUpInside) + button.center = CGPoint(x: (view.frame).midX, y: (view.frame).midY) + button.bgColor = .black + button.color = .white + button.addTarget(self, action: #selector(ViewController.tapped(_:)), for: UIControlEvents.touchUpInside) view.addSubview(button) } - func tapped(sender: AnimatablePlayButton) { - if sender.selected { + func tapped(_ sender: AnimatablePlayButton) { + if sender.isSelected { sender.deselect() } else { sender.select() From e0bf4430d1099cc19b67042d4775ff82cbaa3e97 Mon Sep 17 00:00:00 2001 From: Patrick Aubin Date: Sun, 29 Mar 2020 09:53:27 -0700 Subject: [PATCH 2/2] swift 5 support --- AnimatablePlayButton.xcodeproj/project.pbxproj | 5 +++-- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ AnimatablePlayButton/AnimatablePlayButton.swift | 8 ++++---- 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 AnimatablePlayButton.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/AnimatablePlayButton.xcodeproj/project.pbxproj b/AnimatablePlayButton.xcodeproj/project.pbxproj index 97d9ba4..11f58ee 100644 --- a/AnimatablePlayButton.xcodeproj/project.pbxproj +++ b/AnimatablePlayButton.xcodeproj/project.pbxproj @@ -107,6 +107,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 892EE4341C1EE5FC00A9BE36; @@ -245,7 +246,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -263,7 +264,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.keishi.suzuki.AnimatablePlayButton; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/AnimatablePlayButton.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/AnimatablePlayButton.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/AnimatablePlayButton.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/AnimatablePlayButton/AnimatablePlayButton.swift b/AnimatablePlayButton/AnimatablePlayButton.swift index 0709a3a..94dbb6d 100644 --- a/AnimatablePlayButton/AnimatablePlayButton.swift +++ b/AnimatablePlayButton/AnimatablePlayButton.swift @@ -212,16 +212,16 @@ open class AnimatablePlayButton: UIButton { fileprivate func setPauseProperty(_ animation: CAKeyframeAnimation) { animation.duration = 0.4 - animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn) + animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) animation.isRemovedOnCompletion = false - animation.fillMode = kCAFillModeForwards + animation.fillMode = CAMediaTimingFillMode.forwards } fileprivate func setCommonProperty(_ animation: CAKeyframeAnimation) { animation.duration = 0.4 - animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) + animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear) animation.isRemovedOnCompletion = false - animation.fillMode = kCAFillModeForwards + animation.fillMode = CAMediaTimingFillMode.forwards } // MARK: - public