diff --git a/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO.xcodeproj/project.pbxproj b/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO.xcodeproj/project.pbxproj index 78be48a..4e29189 100644 --- a/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO.xcodeproj/project.pbxproj +++ b/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO.xcodeproj/project.pbxproj @@ -23,6 +23,8 @@ isa = PBXBuildRule; compilerSpec = com.apple.xcode.tools.swift.compiler; fileType = sourcecode.swift; + inputFiles = ( + ); isEditable = 1; outputFiles = ( ); @@ -209,10 +211,11 @@ TargetAttributes = { 4F60711A1B6366ED0058F570 = { CreatedOnToolsVersion = 6.4; - LastSwiftMigration = 0800; + LastSwiftMigration = 1110; }; 4FBAA6FC1B4D807F00C8657F = { CreatedOnToolsVersion = 6.4; + LastSwiftMigration = 1110; }; }; }; @@ -221,6 +224,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -325,7 +329,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -348,7 +352,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "co.devlog.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -448,12 +452,13 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "DOFavoriteButton-DEMO/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "co.devlog.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -462,12 +467,13 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "DOFavoriteButton-DEMO/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "co.devlog.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/AppDelegate.swift b/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/AppDelegate.swift index 3b5e0f9..36e89db 100644 --- a/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/AppDelegate.swift +++ b/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { // Override point for customization after application launch. return true } diff --git a/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/Images.xcassets/AppIcon.appiconset/Contents.json b/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/Images.xcassets/AppIcon.appiconset/Contents.json index 36d2c80..d8db8d6 100644 --- a/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -59,6 +79,16 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/ViewController.swift b/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/ViewController.swift index 70c3acd..a525b57 100644 --- a/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/ViewController.swift +++ b/DOFavoriteButton-DEMO/DOFavoriteButton-DEMO/ViewController.swift @@ -61,7 +61,7 @@ class ViewController: UIViewController { // Dispose of any resources that can be recreated. } - func tappedButton(sender: DOFavoriteButton) { + @objc func tappedButton(sender: DOFavoriteButton) { if sender.isSelected { sender.deselect() } else { diff --git a/DOFavoriteButton/DOFavoriteButton.swift b/DOFavoriteButton/DOFavoriteButton.swift index 47e6d9d..9e5bdbd 100644 --- a/DOFavoriteButton/DOFavoriteButton.swift +++ b/DOFavoriteButton/DOFavoriteButton.swift @@ -17,7 +17,7 @@ open class DOFavoriteButton: UIButton { fileprivate var imageShape: CAShapeLayer! @IBInspectable open var image: UIImage! { didSet { - createLayers(image: image) + createSelectedSampleAnimationLayers(image: image) } } @IBInspectable open var imageColorOn: UIColor! = UIColor(red: 255/255, green: 172/255, blue: 51/255, alpha: 1.0) { @@ -93,17 +93,17 @@ open class DOFavoriteButton: UIButton { public init(frame: CGRect, image: UIImage!) { super.init(frame: frame) self.image = image - createLayers(image: image) + createSelectedSampleAnimationLayers(image: image) addTargets() } public required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder)! - createLayers(image: UIImage()) + createSelectedSampleAnimationLayers(image: UIImage()) addTargets() } - fileprivate func createLayers(image: UIImage!) { + fileprivate func createSelectedSampleAnimationLayers(image: UIImage!) { self.layer.sublayers = nil let imageFrame = CGRect(x: frame.size.width / 2 - frame.size.width / 4, y: frame.size.height / 2 - frame.size.height / 4, width: frame.size.width / 2, height: frame.size.height / 2) @@ -124,11 +124,11 @@ open class DOFavoriteButton: UIButton { circleMask = CAShapeLayer() circleMask.bounds = imageFrame circleMask.position = imgCenterPoint - circleMask.fillRule = kCAFillRuleEvenOdd + circleMask.fillRule = CAShapeLayerFillRule.evenOdd circleShape.mask = circleMask let maskPath = UIBezierPath(rect: imageFrame) - maskPath.addArc(withCenter: imgCenterPoint, radius: 0.1, startAngle: CGFloat(0.0), endAngle: CGFloat(M_PI * 2), clockwise: true) + maskPath.addArc(withCenter: imgCenterPoint, radius: 0.1, startAngle: CGFloat(0.0), endAngle: CGFloat(Double.pi * 2), clockwise: true) circleMask.path = maskPath.cgPath //=============== @@ -150,12 +150,12 @@ open class DOFavoriteButton: UIButton { path.addLine(to: CGPoint(x: lineFrame.origin.x + lineFrame.width / 2, y: lineFrame.origin.y)) return path }() - line.lineCap = kCALineCapRound - line.lineJoin = kCALineJoinRound + line.lineCap = CAShapeLayerLineCap.round + line.lineJoin = CAShapeLayerLineJoin.round line.strokeStart = 0.0 line.strokeEnd = 0.0 line.opacity = 0.0 - line.transform = CATransform3DMakeRotation(CGFloat(M_PI) / 5 * (CGFloat(i) * 2 + 1), 0.0, 0.0, 1.0) + line.transform = CATransform3DMakeRotation(CGFloat(Double.pi) / 5 * (CGFloat(i) * 2 + 1), 0.0, 0.0, 1.0) self.layer.addSublayer(line) lines.append(line) } @@ -338,29 +338,36 @@ open class DOFavoriteButton: UIButton { //=============== // add target //=============== - self.addTarget(self, action: #selector(DOFavoriteButton.touchDown(_:)), for: UIControlEvents.touchDown) - self.addTarget(self, action: #selector(DOFavoriteButton.touchUpInside(_:)), for: UIControlEvents.touchUpInside) - self.addTarget(self, action: #selector(DOFavoriteButton.touchDragExit(_:)), for: UIControlEvents.touchDragExit) - self.addTarget(self, action: #selector(DOFavoriteButton.touchDragEnter(_:)), for: UIControlEvents.touchDragEnter) - self.addTarget(self, action: #selector(DOFavoriteButton.touchCancel(_:)), for: UIControlEvents.touchCancel) + self.addTarget(self, action: #selector(DOFavoriteButton.touchDown(_:)), for: UIControl.Event.touchDown) + self.addTarget(self, action: #selector(DOFavoriteButton.touchUpInside(_:)), for: UIControl.Event.touchUpInside) + self.addTarget(self, action: #selector(DOFavoriteButton.touchDragExit(_:)), for: UIControl.Event.touchDragExit) + self.addTarget(self, action: #selector(DOFavoriteButton.touchDragEnter(_:)), for: UIControl.Event.touchDragEnter) + self.addTarget(self, action: #selector(DOFavoriteButton.touchCancel(_:)), for: UIControl.Event.touchCancel) } - func touchDown(_ sender: DOFavoriteButton) { + @objc func touchDown(_ sender: DOFavoriteButton) { self.layer.opacity = 0.4 } - func touchUpInside(_ sender: DOFavoriteButton) { + @objc func touchUpInside(_ sender: DOFavoriteButton) { self.layer.opacity = 1.0 } - func touchDragExit(_ sender: DOFavoriteButton) { + @objc func touchDragExit(_ sender: DOFavoriteButton) { self.layer.opacity = 1.0 } - func touchDragEnter(_ sender: DOFavoriteButton) { + @objc func touchDragEnter(_ sender: DOFavoriteButton) { self.layer.opacity = 0.4 } - func touchCancel(_ sender: DOFavoriteButton) { + @objc func touchCancel(_ sender: DOFavoriteButton) { self.layer.opacity = 1.0 } + // MARK: - Open Function + + /** + * fileprivateの「createLayers」メソッドで実行したアクションを実行する + * TODO: 自分でCoreAnimationを追加できるような形でプロトコル化をしてみる + */ + open func select() { isSelected = true imageShape.fillColor = imageColorOn.cgColor