├── .gitignore ├── .swift-version ├── Example ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── KYShutterButton.podspec ├── KYShutterButton.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── KYShutterButton.xcscheme ├── KYShutterButton ├── Classes │ └── KYShutterButton.swift ├── Info.plist └── KYShutterButton.h ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 3.1 2 | -------------------------------------------------------------------------------- /Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by kyo__hei on 2016/09/18. 6 | // Copyright © 2016年 kyo__hei. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 109 | 115 | 121 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Example 4 | // 5 | // Created by kyo__hei on 2016/09/18. 6 | // Copyright © 2016年 kyo__hei. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import KYShutterButton 11 | 12 | class ViewController: UIViewController { 13 | 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | // Do any additional setup after loading the view, typically from a nib. 17 | } 18 | 19 | override func didReceiveMemoryWarning() { 20 | super.didReceiveMemoryWarning() 21 | // Dispose of any resources that can be recreated. 22 | } 23 | 24 | @IBAction func didTapButton(_ sender: KYShutterButton) { 25 | switch sender.buttonState { 26 | case .normal: 27 | sender.buttonState = .recording 28 | case .recording: 29 | sender.buttonState = .normal 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /KYShutterButton.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "KYShutterButton" 3 | s.version = "2.0.1" 4 | s.summary = "KYShutterButton is a custom button that is similar to the shutter button of the camera app" 5 | s.homepage = "https://github.com/ykyouhei/KYShutterButton" 6 | s.license = "MIT" 7 | s.author = { "Kyohei Yamaguchi" => "kyouhei.lab@gmail.com" } 8 | s.social_media_url = "https://twitter.com/kyo__hei" 9 | s.platform = :ios, '7.0' 10 | s.source = { :git => "https://github.com/ykyouhei/KYShutterButton.git", :tag => s.version.to_s } 11 | s.source_files = "KYShutterButton/Classes/*.swift" 12 | s.requires_arc = true 13 | s.ios.deployment_target = '8.0' 14 | end 15 | -------------------------------------------------------------------------------- /KYShutterButton.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 410B23461C47E2E30078A5A0 /* KYShutterButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 410B23451C47E2E30078A5A0 /* KYShutterButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | 410B234F1C47E3D00078A5A0 /* KYShutterButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 410B234E1C47E3D00078A5A0 /* KYShutterButton.swift */; }; 12 | 4159763A1D8E805F0007ACF7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 415976391D8E805F0007ACF7 /* AppDelegate.swift */; }; 13 | 4159763C1D8E805F0007ACF7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4159763B1D8E805F0007ACF7 /* ViewController.swift */; }; 14 | 4159763F1D8E805F0007ACF7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4159763D1D8E805F0007ACF7 /* Main.storyboard */; }; 15 | 415976411D8E805F0007ACF7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 415976401D8E805F0007ACF7 /* Assets.xcassets */; }; 16 | 415976441D8E805F0007ACF7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 415976421D8E805F0007ACF7 /* LaunchScreen.storyboard */; }; 17 | 41AF6C201D8E811100A45CFE /* KYShutterButton.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 410B23421C47E2E30078A5A0 /* KYShutterButton.framework */; }; 18 | 41AF6C211D8E811100A45CFE /* KYShutterButton.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 410B23421C47E2E30078A5A0 /* KYShutterButton.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 41AF6C221D8E811100A45CFE /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 410B23391C47E2E30078A5A0 /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 410B23411C47E2E30078A5A0; 27 | remoteInfo = KYShutterButton; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXCopyFilesBuildPhase section */ 32 | 41AF6C241D8E811100A45CFE /* Embed Frameworks */ = { 33 | isa = PBXCopyFilesBuildPhase; 34 | buildActionMask = 2147483647; 35 | dstPath = ""; 36 | dstSubfolderSpec = 10; 37 | files = ( 38 | 41AF6C211D8E811100A45CFE /* KYShutterButton.framework in Embed Frameworks */, 39 | ); 40 | name = "Embed Frameworks"; 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXCopyFilesBuildPhase section */ 44 | 45 | /* Begin PBXFileReference section */ 46 | 410B23421C47E2E30078A5A0 /* KYShutterButton.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = KYShutterButton.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 47 | 410B23451C47E2E30078A5A0 /* KYShutterButton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KYShutterButton.h; sourceTree = ""; }; 48 | 410B23471C47E2E30078A5A0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 49 | 410B234E1C47E3D00078A5A0 /* KYShutterButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KYShutterButton.swift; sourceTree = ""; }; 50 | 415976371D8E805E0007ACF7 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | 415976391D8E805F0007ACF7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 52 | 4159763B1D8E805F0007ACF7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 53 | 4159763E1D8E805F0007ACF7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 54 | 415976401D8E805F0007ACF7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 55 | 415976431D8E805F0007ACF7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 56 | 415976451D8E805F0007ACF7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | /* End PBXFileReference section */ 58 | 59 | /* Begin PBXFrameworksBuildPhase section */ 60 | 410B233E1C47E2E30078A5A0 /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | 415976341D8E805E0007ACF7 /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | 41AF6C201D8E811100A45CFE /* KYShutterButton.framework in Frameworks */, 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | /* End PBXFrameworksBuildPhase section */ 76 | 77 | /* Begin PBXGroup section */ 78 | 410B23381C47E2E30078A5A0 = { 79 | isa = PBXGroup; 80 | children = ( 81 | 410B23441C47E2E30078A5A0 /* KYShutterButton */, 82 | 415976381D8E805F0007ACF7 /* Example */, 83 | 410B23431C47E2E30078A5A0 /* Products */, 84 | ); 85 | sourceTree = ""; 86 | }; 87 | 410B23431C47E2E30078A5A0 /* Products */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 410B23421C47E2E30078A5A0 /* KYShutterButton.framework */, 91 | 415976371D8E805E0007ACF7 /* Example.app */, 92 | ); 93 | name = Products; 94 | sourceTree = ""; 95 | }; 96 | 410B23441C47E2E30078A5A0 /* KYShutterButton */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | 410B234D1C47E3B20078A5A0 /* Classes */, 100 | 410B23451C47E2E30078A5A0 /* KYShutterButton.h */, 101 | 410B23471C47E2E30078A5A0 /* Info.plist */, 102 | ); 103 | path = KYShutterButton; 104 | sourceTree = ""; 105 | }; 106 | 410B234D1C47E3B20078A5A0 /* Classes */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 410B234E1C47E3D00078A5A0 /* KYShutterButton.swift */, 110 | ); 111 | path = Classes; 112 | sourceTree = ""; 113 | }; 114 | 415976381D8E805F0007ACF7 /* Example */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | 415976391D8E805F0007ACF7 /* AppDelegate.swift */, 118 | 4159763B1D8E805F0007ACF7 /* ViewController.swift */, 119 | 4159763D1D8E805F0007ACF7 /* Main.storyboard */, 120 | 415976401D8E805F0007ACF7 /* Assets.xcassets */, 121 | 415976421D8E805F0007ACF7 /* LaunchScreen.storyboard */, 122 | 415976451D8E805F0007ACF7 /* Info.plist */, 123 | ); 124 | path = Example; 125 | sourceTree = ""; 126 | }; 127 | /* End PBXGroup section */ 128 | 129 | /* Begin PBXHeadersBuildPhase section */ 130 | 410B233F1C47E2E30078A5A0 /* Headers */ = { 131 | isa = PBXHeadersBuildPhase; 132 | buildActionMask = 2147483647; 133 | files = ( 134 | 410B23461C47E2E30078A5A0 /* KYShutterButton.h in Headers */, 135 | ); 136 | runOnlyForDeploymentPostprocessing = 0; 137 | }; 138 | /* End PBXHeadersBuildPhase section */ 139 | 140 | /* Begin PBXNativeTarget section */ 141 | 410B23411C47E2E30078A5A0 /* KYShutterButton */ = { 142 | isa = PBXNativeTarget; 143 | buildConfigurationList = 410B234A1C47E2E30078A5A0 /* Build configuration list for PBXNativeTarget "KYShutterButton" */; 144 | buildPhases = ( 145 | 410B233D1C47E2E30078A5A0 /* Sources */, 146 | 410B233E1C47E2E30078A5A0 /* Frameworks */, 147 | 410B233F1C47E2E30078A5A0 /* Headers */, 148 | 410B23401C47E2E30078A5A0 /* Resources */, 149 | ); 150 | buildRules = ( 151 | ); 152 | dependencies = ( 153 | ); 154 | name = KYShutterButton; 155 | productName = KYShutterButton; 156 | productReference = 410B23421C47E2E30078A5A0 /* KYShutterButton.framework */; 157 | productType = "com.apple.product-type.framework"; 158 | }; 159 | 415976361D8E805E0007ACF7 /* Example */ = { 160 | isa = PBXNativeTarget; 161 | buildConfigurationList = 415976481D8E805F0007ACF7 /* Build configuration list for PBXNativeTarget "Example" */; 162 | buildPhases = ( 163 | 415976331D8E805E0007ACF7 /* Sources */, 164 | 415976341D8E805E0007ACF7 /* Frameworks */, 165 | 415976351D8E805E0007ACF7 /* Resources */, 166 | 41AF6C241D8E811100A45CFE /* Embed Frameworks */, 167 | ); 168 | buildRules = ( 169 | ); 170 | dependencies = ( 171 | 41AF6C231D8E811100A45CFE /* PBXTargetDependency */, 172 | ); 173 | name = Example; 174 | productName = Example; 175 | productReference = 415976371D8E805E0007ACF7 /* Example.app */; 176 | productType = "com.apple.product-type.application"; 177 | }; 178 | /* End PBXNativeTarget section */ 179 | 180 | /* Begin PBXProject section */ 181 | 410B23391C47E2E30078A5A0 /* Project object */ = { 182 | isa = PBXProject; 183 | attributes = { 184 | LastSwiftUpdateCheck = 0800; 185 | LastUpgradeCheck = 0800; 186 | ORGANIZATIONNAME = kyo__hei; 187 | TargetAttributes = { 188 | 410B23411C47E2E30078A5A0 = { 189 | CreatedOnToolsVersion = 7.2; 190 | LastSwiftMigration = 0800; 191 | }; 192 | 415976361D8E805E0007ACF7 = { 193 | CreatedOnToolsVersion = 8.0; 194 | ProvisioningStyle = Manual; 195 | }; 196 | }; 197 | }; 198 | buildConfigurationList = 410B233C1C47E2E30078A5A0 /* Build configuration list for PBXProject "KYShutterButton" */; 199 | compatibilityVersion = "Xcode 3.2"; 200 | developmentRegion = English; 201 | hasScannedForEncodings = 0; 202 | knownRegions = ( 203 | en, 204 | Base, 205 | ); 206 | mainGroup = 410B23381C47E2E30078A5A0; 207 | productRefGroup = 410B23431C47E2E30078A5A0 /* Products */; 208 | projectDirPath = ""; 209 | projectRoot = ""; 210 | targets = ( 211 | 410B23411C47E2E30078A5A0 /* KYShutterButton */, 212 | 415976361D8E805E0007ACF7 /* Example */, 213 | ); 214 | }; 215 | /* End PBXProject section */ 216 | 217 | /* Begin PBXResourcesBuildPhase section */ 218 | 410B23401C47E2E30078A5A0 /* Resources */ = { 219 | isa = PBXResourcesBuildPhase; 220 | buildActionMask = 2147483647; 221 | files = ( 222 | ); 223 | runOnlyForDeploymentPostprocessing = 0; 224 | }; 225 | 415976351D8E805E0007ACF7 /* Resources */ = { 226 | isa = PBXResourcesBuildPhase; 227 | buildActionMask = 2147483647; 228 | files = ( 229 | 415976441D8E805F0007ACF7 /* LaunchScreen.storyboard in Resources */, 230 | 415976411D8E805F0007ACF7 /* Assets.xcassets in Resources */, 231 | 4159763F1D8E805F0007ACF7 /* Main.storyboard in Resources */, 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | }; 235 | /* End PBXResourcesBuildPhase section */ 236 | 237 | /* Begin PBXSourcesBuildPhase section */ 238 | 410B233D1C47E2E30078A5A0 /* Sources */ = { 239 | isa = PBXSourcesBuildPhase; 240 | buildActionMask = 2147483647; 241 | files = ( 242 | 410B234F1C47E3D00078A5A0 /* KYShutterButton.swift in Sources */, 243 | ); 244 | runOnlyForDeploymentPostprocessing = 0; 245 | }; 246 | 415976331D8E805E0007ACF7 /* Sources */ = { 247 | isa = PBXSourcesBuildPhase; 248 | buildActionMask = 2147483647; 249 | files = ( 250 | 4159763C1D8E805F0007ACF7 /* ViewController.swift in Sources */, 251 | 4159763A1D8E805F0007ACF7 /* AppDelegate.swift in Sources */, 252 | ); 253 | runOnlyForDeploymentPostprocessing = 0; 254 | }; 255 | /* End PBXSourcesBuildPhase section */ 256 | 257 | /* Begin PBXTargetDependency section */ 258 | 41AF6C231D8E811100A45CFE /* PBXTargetDependency */ = { 259 | isa = PBXTargetDependency; 260 | target = 410B23411C47E2E30078A5A0 /* KYShutterButton */; 261 | targetProxy = 41AF6C221D8E811100A45CFE /* PBXContainerItemProxy */; 262 | }; 263 | /* End PBXTargetDependency section */ 264 | 265 | /* Begin PBXVariantGroup section */ 266 | 4159763D1D8E805F0007ACF7 /* Main.storyboard */ = { 267 | isa = PBXVariantGroup; 268 | children = ( 269 | 4159763E1D8E805F0007ACF7 /* Base */, 270 | ); 271 | name = Main.storyboard; 272 | sourceTree = ""; 273 | }; 274 | 415976421D8E805F0007ACF7 /* LaunchScreen.storyboard */ = { 275 | isa = PBXVariantGroup; 276 | children = ( 277 | 415976431D8E805F0007ACF7 /* Base */, 278 | ); 279 | name = LaunchScreen.storyboard; 280 | sourceTree = ""; 281 | }; 282 | /* End PBXVariantGroup section */ 283 | 284 | /* Begin XCBuildConfiguration section */ 285 | 410B23481C47E2E30078A5A0 /* Debug */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ALWAYS_SEARCH_USER_PATHS = NO; 289 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 290 | CLANG_CXX_LIBRARY = "libc++"; 291 | CLANG_ENABLE_MODULES = YES; 292 | CLANG_ENABLE_OBJC_ARC = YES; 293 | CLANG_WARN_BOOL_CONVERSION = YES; 294 | CLANG_WARN_CONSTANT_CONVERSION = YES; 295 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 296 | CLANG_WARN_EMPTY_BODY = YES; 297 | CLANG_WARN_ENUM_CONVERSION = YES; 298 | CLANG_WARN_INFINITE_RECURSION = YES; 299 | CLANG_WARN_INT_CONVERSION = YES; 300 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 301 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 302 | CLANG_WARN_UNREACHABLE_CODE = YES; 303 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 304 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 305 | COPY_PHASE_STRIP = NO; 306 | CURRENT_PROJECT_VERSION = 1; 307 | DEBUG_INFORMATION_FORMAT = dwarf; 308 | ENABLE_STRICT_OBJC_MSGSEND = YES; 309 | ENABLE_TESTABILITY = YES; 310 | GCC_C_LANGUAGE_STANDARD = gnu99; 311 | GCC_DYNAMIC_NO_PIC = NO; 312 | GCC_NO_COMMON_BLOCKS = YES; 313 | GCC_OPTIMIZATION_LEVEL = 0; 314 | GCC_PREPROCESSOR_DEFINITIONS = ( 315 | "DEBUG=1", 316 | "$(inherited)", 317 | ); 318 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 319 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 320 | GCC_WARN_UNDECLARED_SELECTOR = YES; 321 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 322 | GCC_WARN_UNUSED_FUNCTION = YES; 323 | GCC_WARN_UNUSED_VARIABLE = YES; 324 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 325 | MTL_ENABLE_DEBUG_INFO = YES; 326 | ONLY_ACTIVE_ARCH = YES; 327 | SDKROOT = iphoneos; 328 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 329 | TARGETED_DEVICE_FAMILY = "1,2"; 330 | VERSIONING_SYSTEM = "apple-generic"; 331 | VERSION_INFO_PREFIX = ""; 332 | }; 333 | name = Debug; 334 | }; 335 | 410B23491C47E2E30078A5A0 /* Release */ = { 336 | isa = XCBuildConfiguration; 337 | buildSettings = { 338 | ALWAYS_SEARCH_USER_PATHS = NO; 339 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 340 | CLANG_CXX_LIBRARY = "libc++"; 341 | CLANG_ENABLE_MODULES = YES; 342 | CLANG_ENABLE_OBJC_ARC = YES; 343 | CLANG_WARN_BOOL_CONVERSION = YES; 344 | CLANG_WARN_CONSTANT_CONVERSION = YES; 345 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 346 | CLANG_WARN_EMPTY_BODY = YES; 347 | CLANG_WARN_ENUM_CONVERSION = YES; 348 | CLANG_WARN_INFINITE_RECURSION = YES; 349 | CLANG_WARN_INT_CONVERSION = YES; 350 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 351 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 352 | CLANG_WARN_UNREACHABLE_CODE = YES; 353 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 354 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 355 | COPY_PHASE_STRIP = NO; 356 | CURRENT_PROJECT_VERSION = 1; 357 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 358 | ENABLE_NS_ASSERTIONS = NO; 359 | ENABLE_STRICT_OBJC_MSGSEND = YES; 360 | GCC_C_LANGUAGE_STANDARD = gnu99; 361 | GCC_NO_COMMON_BLOCKS = YES; 362 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 363 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 364 | GCC_WARN_UNDECLARED_SELECTOR = YES; 365 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 366 | GCC_WARN_UNUSED_FUNCTION = YES; 367 | GCC_WARN_UNUSED_VARIABLE = YES; 368 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 369 | MTL_ENABLE_DEBUG_INFO = NO; 370 | SDKROOT = iphoneos; 371 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 372 | TARGETED_DEVICE_FAMILY = "1,2"; 373 | VALIDATE_PRODUCT = YES; 374 | VERSIONING_SYSTEM = "apple-generic"; 375 | VERSION_INFO_PREFIX = ""; 376 | }; 377 | name = Release; 378 | }; 379 | 410B234B1C47E2E30078A5A0 /* Debug */ = { 380 | isa = XCBuildConfiguration; 381 | buildSettings = { 382 | CLANG_ENABLE_MODULES = YES; 383 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 384 | DEFINES_MODULE = YES; 385 | DEVELOPMENT_TEAM = ""; 386 | DYLIB_COMPATIBILITY_VERSION = 1; 387 | DYLIB_CURRENT_VERSION = 1; 388 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 389 | INFOPLIST_FILE = KYShutterButton/Info.plist; 390 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 391 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 392 | PRODUCT_BUNDLE_IDENTIFIER = "com.kyo--hei.KYShutterButton"; 393 | PRODUCT_NAME = "$(TARGET_NAME)"; 394 | SKIP_INSTALL = YES; 395 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 396 | SWIFT_VERSION = 3.0; 397 | }; 398 | name = Debug; 399 | }; 400 | 410B234C1C47E2E30078A5A0 /* Release */ = { 401 | isa = XCBuildConfiguration; 402 | buildSettings = { 403 | CLANG_ENABLE_MODULES = YES; 404 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 405 | DEFINES_MODULE = YES; 406 | DEVELOPMENT_TEAM = ""; 407 | DYLIB_COMPATIBILITY_VERSION = 1; 408 | DYLIB_CURRENT_VERSION = 1; 409 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 410 | INFOPLIST_FILE = KYShutterButton/Info.plist; 411 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 412 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 413 | PRODUCT_BUNDLE_IDENTIFIER = "com.kyo--hei.KYShutterButton"; 414 | PRODUCT_NAME = "$(TARGET_NAME)"; 415 | SKIP_INSTALL = YES; 416 | SWIFT_VERSION = 3.0; 417 | }; 418 | name = Release; 419 | }; 420 | 415976461D8E805F0007ACF7 /* Debug */ = { 421 | isa = XCBuildConfiguration; 422 | buildSettings = { 423 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 424 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 425 | CLANG_ANALYZER_NONNULL = YES; 426 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 427 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 428 | DEVELOPMENT_TEAM = ""; 429 | INFOPLIST_FILE = Example/Info.plist; 430 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 431 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 432 | PRODUCT_BUNDLE_IDENTIFIER = "com.kyo--hei.Example"; 433 | PRODUCT_NAME = "$(TARGET_NAME)"; 434 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 435 | SWIFT_VERSION = 3.0; 436 | TARGETED_DEVICE_FAMILY = 1; 437 | }; 438 | name = Debug; 439 | }; 440 | 415976471D8E805F0007ACF7 /* Release */ = { 441 | isa = XCBuildConfiguration; 442 | buildSettings = { 443 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 444 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 445 | CLANG_ANALYZER_NONNULL = YES; 446 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 447 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 448 | DEVELOPMENT_TEAM = ""; 449 | INFOPLIST_FILE = Example/Info.plist; 450 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 451 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 452 | PRODUCT_BUNDLE_IDENTIFIER = "com.kyo--hei.Example"; 453 | PRODUCT_NAME = "$(TARGET_NAME)"; 454 | SWIFT_VERSION = 3.0; 455 | TARGETED_DEVICE_FAMILY = 1; 456 | }; 457 | name = Release; 458 | }; 459 | /* End XCBuildConfiguration section */ 460 | 461 | /* Begin XCConfigurationList section */ 462 | 410B233C1C47E2E30078A5A0 /* Build configuration list for PBXProject "KYShutterButton" */ = { 463 | isa = XCConfigurationList; 464 | buildConfigurations = ( 465 | 410B23481C47E2E30078A5A0 /* Debug */, 466 | 410B23491C47E2E30078A5A0 /* Release */, 467 | ); 468 | defaultConfigurationIsVisible = 0; 469 | defaultConfigurationName = Release; 470 | }; 471 | 410B234A1C47E2E30078A5A0 /* Build configuration list for PBXNativeTarget "KYShutterButton" */ = { 472 | isa = XCConfigurationList; 473 | buildConfigurations = ( 474 | 410B234B1C47E2E30078A5A0 /* Debug */, 475 | 410B234C1C47E2E30078A5A0 /* Release */, 476 | ); 477 | defaultConfigurationIsVisible = 0; 478 | defaultConfigurationName = Release; 479 | }; 480 | 415976481D8E805F0007ACF7 /* Build configuration list for PBXNativeTarget "Example" */ = { 481 | isa = XCConfigurationList; 482 | buildConfigurations = ( 483 | 415976461D8E805F0007ACF7 /* Debug */, 484 | 415976471D8E805F0007ACF7 /* Release */, 485 | ); 486 | defaultConfigurationIsVisible = 0; 487 | defaultConfigurationName = Release; 488 | }; 489 | /* End XCConfigurationList section */ 490 | }; 491 | rootObject = 410B23391C47E2E30078A5A0 /* Project object */; 492 | } 493 | -------------------------------------------------------------------------------- /KYShutterButton.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /KYShutterButton.xcodeproj/xcshareddata/xcschemes/KYShutterButton.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /KYShutterButton/Classes/KYShutterButton.swift: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2015 Kyohei Yamaguchi 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | import UIKit 26 | 27 | @objc 28 | @IBDesignable 29 | open class KYShutterButton: UIButton { 30 | 31 | @objc 32 | public enum ShutterType: Int { 33 | case normal, slowMotion, timeLapse 34 | } 35 | 36 | @objc 37 | public enum ButtonState: Int { 38 | case normal, recording 39 | } 40 | 41 | private let _kstartAnimateDuration: CFTimeInterval = 0.5 42 | 43 | /**************************************************************************/ 44 | // MARK: - Properties 45 | /**************************************************************************/ 46 | 47 | @objc 48 | @IBInspectable var typeRaw: Int = 0 { 49 | didSet { 50 | if let type = ShutterType(rawValue: typeRaw) { 51 | self.shutterType = type 52 | } else { 53 | self.shutterType = .normal 54 | } 55 | } 56 | } 57 | 58 | @objc 59 | @IBInspectable public var buttonColor: UIColor = UIColor.red { 60 | didSet { 61 | _circleLayer.fillColor = buttonColor.cgColor 62 | } 63 | } 64 | 65 | @objc 66 | @IBInspectable public var arcColor: UIColor = UIColor.white { 67 | didSet { 68 | _arcLayer.strokeColor = arcColor.cgColor 69 | } 70 | } 71 | 72 | @objc 73 | @IBInspectable public var progressColor: UIColor = UIColor.white { 74 | didSet { 75 | _progressLayer.strokeColor = progressColor.cgColor 76 | _rotateLayer.strokeColor = progressColor.cgColor 77 | } 78 | } 79 | 80 | @objc 81 | @IBInspectable public var rotateAnimateDuration: Float = 5 { 82 | didSet { 83 | _recordingRotateAnimation.duration = TimeInterval(rotateAnimateDuration) 84 | _recordingAnimation.duration = TimeInterval(rotateAnimateDuration*2) 85 | } 86 | } 87 | 88 | @objc 89 | public var buttonState: ButtonState = .normal { 90 | didSet { 91 | let animation = CABasicAnimation(keyPath: "path") 92 | animation.fromValue = _circleLayer.path 93 | animation.duration = 0.15 94 | 95 | switch buttonState { 96 | case .normal: 97 | if shutterType == .timeLapse { 98 | p_removeTimeLapseAnimations() 99 | } 100 | animation.toValue = _circlePath.cgPath 101 | _circleLayer.add(animation, forKey: "path-anim") 102 | _circleLayer.path = _circlePath.cgPath 103 | case .recording: 104 | animation.toValue = _roundRectPath.cgPath 105 | _circleLayer.add(animation, forKey: "path-anim") 106 | _circleLayer.path = _roundRectPath.cgPath 107 | if shutterType == .timeLapse { 108 | p_addTimeLapseAnimations() 109 | } 110 | } 111 | } 112 | } 113 | 114 | @objc 115 | public var shutterType: ShutterType = .normal { 116 | didSet { 117 | updateLayers() 118 | } 119 | } 120 | 121 | private var _arcWidth: CGFloat { 122 | return bounds.width * 0.09090 123 | } 124 | 125 | private var _arcMargin: CGFloat { 126 | return bounds.width * 0.03030 127 | } 128 | 129 | lazy private var _circleLayer: CAShapeLayer = { 130 | let layer = CAShapeLayer() 131 | layer.path = self._circlePath.cgPath 132 | layer.fillColor = self.buttonColor.cgColor 133 | return layer 134 | }() 135 | 136 | lazy private var _arcLayer: CAShapeLayer = { 137 | let layer = CAShapeLayer() 138 | layer.path = self._arcPath.cgPath 139 | layer.fillColor = UIColor.clear.cgColor 140 | layer.strokeColor = self.arcColor.cgColor 141 | layer.lineWidth = self._arcWidth 142 | return layer 143 | }() 144 | 145 | lazy private var _progressLayer: CAShapeLayer = { 146 | let layer = CAShapeLayer() 147 | let path = self.p_arcPathWithProgress(1.0, clockwise: true) 148 | layer.path = path.cgPath 149 | layer.fillColor = UIColor.clear.cgColor 150 | layer.strokeColor = self.progressColor.cgColor 151 | layer.lineWidth = self._arcWidth/1.5 152 | return layer 153 | }() 154 | 155 | lazy private var _rotateLayer: CAShapeLayer = { 156 | let layer = CAShapeLayer() 157 | layer.strokeColor = self.progressColor.cgColor 158 | layer.lineWidth = 1 159 | layer.path = self._rotatePath.cgPath 160 | layer.frame = self.bounds 161 | return layer 162 | }() 163 | 164 | private var _circlePath: UIBezierPath { 165 | let side = self.bounds.width - self._arcWidth*2 - self._arcMargin*2 166 | return UIBezierPath( 167 | roundedRect: CGRect(x: bounds.width/2 - side/2, y: bounds.width/2 - side/2, width: side, height: side), 168 | cornerRadius: side/2 169 | ) 170 | } 171 | 172 | private var _arcPath: UIBezierPath { 173 | return UIBezierPath( 174 | arcCenter: CGPoint(x: self.bounds.midX, y: self.bounds.midY), 175 | radius: self.bounds.width/2 - self._arcWidth/2, 176 | startAngle: -.pi/2, 177 | endAngle: .pi*2 - .pi/2, 178 | clockwise: true 179 | ) 180 | } 181 | 182 | private var _roundRectPath: UIBezierPath { 183 | let side = bounds.width * 0.4242 184 | return UIBezierPath( 185 | roundedRect: CGRect(x: bounds.width/2 - side/2, y: bounds.width/2 - side/2, width: side, height: side), 186 | cornerRadius: side * 0.107 187 | ) 188 | } 189 | 190 | private var _rotatePath: UIBezierPath { 191 | let path = UIBezierPath() 192 | path.move(to: CGPoint(x: self.bounds.width/2, y: 0)) 193 | path.addLine(to: CGPoint(x: self.bounds.width/2, y: self._arcWidth)) 194 | return path 195 | } 196 | 197 | private var _startProgressAnimation: CAKeyframeAnimation { 198 | let frameCount = 60 199 | var paths = [CGPath]() 200 | var times = [CGFloat]() 201 | for i in 1...frameCount { 202 | let animationProgress = 1/CGFloat(frameCount) * CGFloat(i) - 0.01 203 | paths.append(self.p_arcPathWithProgress(animationProgress, clockwise: false).cgPath) 204 | times.append(CGFloat(i)*0.1) 205 | } 206 | let animation = CAKeyframeAnimation(keyPath: "path") 207 | animation.duration = _kstartAnimateDuration 208 | animation.values = paths 209 | return animation 210 | } 211 | 212 | private var _startRotateAnimation: CABasicAnimation { 213 | let animation = CABasicAnimation(keyPath: "transform.rotation.z") 214 | animation.fromValue = 0 215 | animation.toValue = CGFloat.pi*2 216 | animation.duration = _kstartAnimateDuration 217 | return animation 218 | } 219 | 220 | private var _recordingAnimation: CAKeyframeAnimation { 221 | let frameCount = 60 222 | var paths = [CGPath]() 223 | for i in 1...frameCount { 224 | let animationProgress = 1/CGFloat(frameCount) * CGFloat(i) 225 | paths.append(self.p_arcPathWithProgress(animationProgress).cgPath) 226 | } 227 | for i in 1...frameCount { 228 | let animationProgress = 1/CGFloat(frameCount) * CGFloat(i) - 0.01 229 | paths.append(self.p_arcPathWithProgress(animationProgress, clockwise: false).cgPath) 230 | } 231 | let animation = CAKeyframeAnimation(keyPath: "path") 232 | animation.duration = TimeInterval(rotateAnimateDuration*2) 233 | animation.values = paths 234 | animation.beginTime = CACurrentMediaTime() + _kstartAnimateDuration 235 | animation.repeatCount = Float.infinity 236 | animation.calculationMode = kCAAnimationDiscrete 237 | return animation 238 | } 239 | 240 | private var _recordingRotateAnimation: CABasicAnimation { 241 | let animation = CABasicAnimation(keyPath: "transform.rotation") 242 | animation.fromValue = 0 243 | animation.toValue = CGFloat.pi*2 244 | animation.duration = TimeInterval(rotateAnimateDuration) 245 | animation.repeatCount = Float.infinity 246 | animation.beginTime = CACurrentMediaTime() + _kstartAnimateDuration 247 | return animation 248 | } 249 | 250 | 251 | /**************************************************************************/ 252 | // MARK: - initialize 253 | /**************************************************************************/ 254 | 255 | @objc 256 | public convenience init(frame: CGRect, shutterType: ShutterType, buttonColor: UIColor) { 257 | self.init(frame: frame) 258 | self.shutterType = shutterType 259 | self.buttonColor = buttonColor 260 | } 261 | 262 | /**************************************************************************/ 263 | // MARK: - Override 264 | /**************************************************************************/ 265 | 266 | @objc 267 | override open var isHighlighted: Bool { 268 | didSet { 269 | _circleLayer.opacity = isHighlighted ? 0.5 : 1.0 270 | } 271 | } 272 | 273 | @objc 274 | open override func layoutSubviews() { 275 | super.layoutSubviews() 276 | if _arcLayer.superlayer != layer { 277 | layer.addSublayer(_arcLayer) 278 | } else { 279 | _arcLayer.path = _arcPath.cgPath 280 | _arcLayer.lineWidth = _arcWidth 281 | } 282 | 283 | if _progressLayer.superlayer != layer { 284 | layer.addSublayer(_progressLayer) 285 | } else { 286 | _progressLayer.path = p_arcPathWithProgress(1).cgPath 287 | _progressLayer.lineWidth = _arcWidth/1.5 288 | } 289 | 290 | if _rotateLayer.superlayer != layer { 291 | layer.insertSublayer(_rotateLayer, at: 0) 292 | } else { 293 | _rotateLayer.path = _rotatePath.cgPath 294 | _rotateLayer.frame = self.bounds 295 | } 296 | 297 | if _circleLayer.superlayer != layer { 298 | layer.addSublayer(_circleLayer) 299 | } else { 300 | switch buttonState { 301 | case .normal: _circleLayer.path = _circlePath.cgPath 302 | case .recording: _circleLayer.path = _roundRectPath.cgPath 303 | } 304 | } 305 | 306 | if shutterType == .timeLapse && buttonState == .recording { 307 | p_removeTimeLapseAnimations() 308 | p_addTimeLapseAnimations() 309 | } 310 | 311 | updateLayers() 312 | } 313 | 314 | @objc 315 | open override func setTitle(_ title: String?, for state: UIControlState) { 316 | super.setTitle("", for: state) 317 | } 318 | 319 | /**************************************************************************/ 320 | // MARK: - Method 321 | /**************************************************************************/ 322 | 323 | private func p_addTimeLapseAnimations() { 324 | _progressLayer.add(_startProgressAnimation, forKey: "start-anim") 325 | _rotateLayer.add(_startRotateAnimation, forKey: "rotate-anim") 326 | _progressLayer.add(_recordingAnimation, forKey: "recording-anim") 327 | _rotateLayer.add(_recordingRotateAnimation, forKey: "recordingRotate-anim") 328 | _progressLayer.path = p_arcPathWithProgress(1.0).cgPath 329 | } 330 | 331 | private func p_removeTimeLapseAnimations() { 332 | _progressLayer.removeAllAnimations() 333 | _rotateLayer.removeAllAnimations() 334 | } 335 | 336 | private func p_arcPathWithProgress(_ progress: CGFloat, clockwise: Bool = true) -> UIBezierPath { 337 | let diameter = 2*CGFloat.pi*(self.bounds.width/2 - self._arcWidth/3) 338 | let startAngle = clockwise ? 339 | -CGFloat.pi/2 : 340 | -CGFloat.pi/2 + CGFloat.pi*(540/diameter)/180 341 | let endAngle = clockwise ? 342 | CGFloat.pi*2*progress - CGFloat.pi/2 : 343 | CGFloat.pi*2*progress - CGFloat.pi/2 + CGFloat.pi*(540/diameter)/180 344 | let path = UIBezierPath( 345 | arcCenter: CGPoint(x: self.bounds.midX, y: self.bounds.midY), 346 | radius: self.bounds.width/2 - self._arcWidth/3, 347 | startAngle: startAngle, 348 | endAngle: endAngle, 349 | clockwise: clockwise 350 | ) 351 | return path 352 | } 353 | 354 | private func updateLayers() { 355 | switch shutterType { 356 | case .normal: 357 | _arcLayer.lineDashPattern = nil 358 | _progressLayer.isHidden = true 359 | case .slowMotion: 360 | _arcLayer.lineDashPattern = [1, 1] 361 | _progressLayer.isHidden = true 362 | case .timeLapse: 363 | let diameter = CGFloat.pi*(self.bounds.width/2 - self._arcWidth/2) 364 | let progressDiameter = 2*CGFloat.pi*(self.bounds.width/2 - self._arcWidth/3) 365 | 366 | _arcLayer.lineDashPattern = [1, NSNumber(value: (diameter/10 - 1).native)] 367 | _progressLayer.lineDashPattern = [1, NSNumber(value: (progressDiameter/60 - 1).native)] 368 | _progressLayer.isHidden = false 369 | } 370 | } 371 | 372 | } 373 | -------------------------------------------------------------------------------- /KYShutterButton/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 2.0.1 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /KYShutterButton/KYShutterButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // KYShutterButton.h 3 | // KYShutterButton 4 | // 5 | // Created by kyo__hei on 2016/01/14. 6 | // Copyright © 2016年 kyo__hei. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for KYShutterButton. 12 | FOUNDATION_EXPORT double KYShutterButtonVersionNumber; 13 | 14 | //! Project version string for KYShutterButton. 15 | FOUNDATION_EXPORT const unsigned char KYShutterButtonVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Kyohei Yamaguchi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KYShutterButton 2 | 3 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 4 | [![Pod Version](http://img.shields.io/cocoapods/v/KYShutterButton.svg?style=flat)](http://cocoadocs.org/docsets/KYShutterButton/) 5 | [![Pod Platform](http://img.shields.io/cocoapods/p/KYShutterButton.svg?style=flat)](http://cocoadocs.org/docsets/KYShutterButton/) 6 | [![Pod License](http://img.shields.io/cocoapods/l/KYShutterButton.svg?style=flat)](https://github.com/ykyohei/KYShutterButton/blob/master/LICENSE) 7 | ![Swift version](https://img.shields.io/badge/swift-3.1-orange.svg) 8 | 9 | 10 | `KYShutterButton` is a custom button that is similar to the shutter button of the camera app 11 | 12 | * IBDesignable, IBInspectable Support 13 | 14 | 15 | ![sample1.gif](https://cloud.githubusercontent.com/assets/5757351/8271385/a614921e-184f-11e5-9a64-efcd0c1cd0e2.gif "sample.gif") ![sample2.gif](https://cloud.githubusercontent.com/assets/5757351/8271386/aa7808cc-184f-11e5-8766-6c5f56a3d1f0.gif "sample2.gif") 16 | 17 | 18 | ## Installation 19 | 20 | ### CocoaPods 21 | 22 | `KYShutterButton ` is available on CocoaPods. 23 | Add the following to your `Podfile`: 24 | 25 | ```ruby 26 | pod 'KYShutterButton' 27 | ``` 28 | 29 | ### Manually 30 | Just add the Classes folder to your project. 31 | 32 | 33 | ## Usage 34 | (see sample Xcode project in `/Example`) 35 | 36 | ### Code 37 | 38 | ```Swift 39 | let shutterButton = KYShutterButton( 40 | frame: CGRectMake(20, 20, 100, 100), 41 | shutterType: .Normal, 42 | buttonColor: UIColor.redColor() 43 | ) 44 | shutterButton.addTarget(self, 45 | action: "didTapButton:", 46 | forControlEvents: .TouchUpInside 47 | ) 48 | /* Custom 49 | shutterButton.arcColor = UIColor.greenColor() 50 | shutterButton.progressColor = UIColor.yellowColor() 51 | */ 52 | view.addSubview(shutterButton) 53 | 54 | 55 | func didTapButton(sender: KYShutterButton) { 56 | switch sender.buttonState { 57 | case .Normal: 58 | sender.buttonState = .Recording 59 | case .Recording: 60 | sender.buttonState = .Normal 61 | } 62 | } 63 | ``` 64 | 65 | ### Storyboard 66 | 67 | ![sample3.gif](https://cloud.githubusercontent.com/assets/5757351/8271468/8f97aab2-1854-11e5-87e6-2ac7e17951a7.gif "sample3.gif") 68 | 69 | 70 | ## License 71 | 72 | This code is distributed under the terms and conditions of the [MIT license](LICENSE). 73 | --------------------------------------------------------------------------------