├── .gitignore ├── FluidInterfaces ├── FluidInterfaces.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── FluidInterfaces │ ├── Acceleration.swift │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── icon.png │ │ ├── icon120.png │ │ ├── icon152.png │ │ ├── icon167.png │ │ └── icon180.png │ ├── Contents.json │ ├── chevron.imageset │ │ ├── Contents.json │ │ └── chevron.pdf │ ├── flashlight_off.imageset │ │ ├── Contents.json │ │ └── flashlight_off.pdf │ ├── flashlight_on.imageset │ │ ├── Contents.json │ │ └── flashlight_on.pdf │ ├── icon_acceleration.imageset │ │ ├── Contents.json │ │ └── icon_acceleration.png │ ├── icon_calc.imageset │ │ ├── Contents.json │ │ └── icon_calc.png │ ├── icon_flash.imageset │ │ ├── Contents.json │ │ └── icon_flash.png │ ├── icon_momentum.imageset │ │ ├── Contents.json │ │ └── icon_momentum.png │ ├── icon_pip.imageset │ │ ├── Contents.json │ │ └── icon_pip.png │ ├── icon_rotation.imageset │ │ ├── Contents.json │ │ └── icon_rotation.png │ ├── icon_rubber.imageset │ │ ├── Contents.json │ │ └── icon_rubber.png │ └── icon_spring.imageset │ │ ├── Contents.json │ │ └── icon_spring.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── CGPointExtensions.swift │ ├── CalculatorButton.swift │ ├── FlashlightButton.swift │ ├── GradientView.swift │ ├── Info.plist │ ├── Interface.swift │ ├── InterfaceViewController.swift │ ├── MenuViewController.swift │ ├── Momentum.swift │ ├── Pip.swift │ ├── Rotation.swift │ ├── Rubberbanding.swift │ ├── Spring.swift │ ├── SwiftExtensions.swift │ ├── UIColorExtensions.swift │ └── UIViewExtensions.swift ├── LICENSE ├── README.md └── Resources ├── accelerationdemo.gif ├── calcdemo.gif ├── flashdemo.gif ├── momentumdemo.gif ├── pipdemo.gif ├── repo-banner.png ├── rotationdemo.gif ├── rubberdemo.gif └── springdemo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | 51 | # Carthage 52 | # 53 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 54 | # Carthage/Checkouts 55 | 56 | Carthage/Build 57 | 58 | # fastlane 59 | # 60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 61 | # screenshots whenever they are needed. 62 | # For more information about the recommended setup visit: 63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 64 | 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots/**/*.png 68 | fastlane/test_output 69 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D806B89020F8275600740219 /* UIColorExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D806B88F20F8275600740219 /* UIColorExtensions.swift */; }; 11 | D806B89220F82A3700740219 /* UIViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D806B89120F82A3700740219 /* UIViewExtensions.swift */; }; 12 | D8409D0A20FBDA8100C7DCD2 /* CGPointExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8409D0920FBDA8100C7DCD2 /* CGPointExtensions.swift */; }; 13 | D8409D0C20FC010B00C7DCD2 /* GradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8409D0B20FC010B00C7DCD2 /* GradientView.swift */; }; 14 | D8757E7220F124BD00D7EB4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8757E7120F124BD00D7EB4E /* AppDelegate.swift */; }; 15 | D8757E7420F124BD00D7EB4E /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8757E7320F124BD00D7EB4E /* MenuViewController.swift */; }; 16 | D8757E7720F124BD00D7EB4E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D8757E7520F124BD00D7EB4E /* Main.storyboard */; }; 17 | D8757E7920F124BF00D7EB4E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D8757E7820F124BF00D7EB4E /* Assets.xcassets */; }; 18 | D8757E7C20F124BF00D7EB4E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D8757E7A20F124BF00D7EB4E /* LaunchScreen.storyboard */; }; 19 | D8976AB220F2B2FA00E148CB /* Interface.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8976AB120F2B2FA00E148CB /* Interface.swift */; }; 20 | D8976AB420F2B3A400E148CB /* InterfaceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8976AB320F2B3A400E148CB /* InterfaceViewController.swift */; }; 21 | D8976AB620F2B3D900E148CB /* CalculatorButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8976AB520F2B3D900E148CB /* CalculatorButton.swift */; }; 22 | D8976AB820F2D38E00E148CB /* FlashlightButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8976AB720F2D38E00E148CB /* FlashlightButton.swift */; }; 23 | D8976ABA20F2D3B500E148CB /* Rubberbanding.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8976AB920F2D3B500E148CB /* Rubberbanding.swift */; }; 24 | D8976ABC20F2D3DC00E148CB /* Spring.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8976ABB20F2D3DC00E148CB /* Spring.swift */; }; 25 | D8976ABE20F2D3FA00E148CB /* Acceleration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8976ABD20F2D3FA00E148CB /* Acceleration.swift */; }; 26 | D8976AC020F2D42200E148CB /* Momentum.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8976ABF20F2D42200E148CB /* Momentum.swift */; }; 27 | D8976AC220F2D44C00E148CB /* Pip.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8976AC120F2D44C00E148CB /* Pip.swift */; }; 28 | D8976AC620F2D48800E148CB /* Rotation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8976AC520F2D48800E148CB /* Rotation.swift */; }; 29 | E70E61792129959E00633473 /* SwiftExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E70E61782129959E00633473 /* SwiftExtensions.swift */; }; 30 | /* End PBXBuildFile section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | D806B88F20F8275600740219 /* UIColorExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColorExtensions.swift; sourceTree = ""; }; 34 | D806B89120F82A3700740219 /* UIViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewExtensions.swift; sourceTree = ""; }; 35 | D8409D0920FBDA8100C7DCD2 /* CGPointExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CGPointExtensions.swift; sourceTree = ""; }; 36 | D8409D0B20FC010B00C7DCD2 /* GradientView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientView.swift; sourceTree = ""; }; 37 | D8757E6E20F124BD00D7EB4E /* FluidInterfaces.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FluidInterfaces.app; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | D8757E7120F124BD00D7EB4E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | D8757E7320F124BD00D7EB4E /* MenuViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuViewController.swift; sourceTree = ""; }; 40 | D8757E7620F124BD00D7EB4E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 41 | D8757E7820F124BF00D7EB4E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 42 | D8757E7B20F124BF00D7EB4E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 43 | D8757E7D20F124BF00D7EB4E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | D8976AB120F2B2FA00E148CB /* Interface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Interface.swift; sourceTree = ""; }; 45 | D8976AB320F2B3A400E148CB /* InterfaceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterfaceViewController.swift; sourceTree = ""; }; 46 | D8976AB520F2B3D900E148CB /* CalculatorButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalculatorButton.swift; sourceTree = ""; }; 47 | D8976AB720F2D38E00E148CB /* FlashlightButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashlightButton.swift; sourceTree = ""; }; 48 | D8976AB920F2D3B500E148CB /* Rubberbanding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rubberbanding.swift; sourceTree = ""; }; 49 | D8976ABB20F2D3DC00E148CB /* Spring.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Spring.swift; sourceTree = ""; }; 50 | D8976ABD20F2D3FA00E148CB /* Acceleration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Acceleration.swift; sourceTree = ""; }; 51 | D8976ABF20F2D42200E148CB /* Momentum.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Momentum.swift; sourceTree = ""; }; 52 | D8976AC120F2D44C00E148CB /* Pip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pip.swift; sourceTree = ""; }; 53 | D8976AC520F2D48800E148CB /* Rotation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rotation.swift; sourceTree = ""; }; 54 | E70E61782129959E00633473 /* SwiftExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftExtensions.swift; sourceTree = ""; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | D8757E6B20F124BD00D7EB4E /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | /* End PBXFrameworksBuildPhase section */ 66 | 67 | /* Begin PBXGroup section */ 68 | D8757E6520F124BD00D7EB4E = { 69 | isa = PBXGroup; 70 | children = ( 71 | D8757E7020F124BD00D7EB4E /* FluidInterfaces */, 72 | D8757E6F20F124BD00D7EB4E /* Products */, 73 | ); 74 | sourceTree = ""; 75 | }; 76 | D8757E6F20F124BD00D7EB4E /* Products */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | D8757E6E20F124BD00D7EB4E /* FluidInterfaces.app */, 80 | ); 81 | name = Products; 82 | sourceTree = ""; 83 | }; 84 | D8757E7020F124BD00D7EB4E /* FluidInterfaces */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | D8757E7120F124BD00D7EB4E /* AppDelegate.swift */, 88 | D8976AB120F2B2FA00E148CB /* Interface.swift */, 89 | D8757E7320F124BD00D7EB4E /* MenuViewController.swift */, 90 | D8976AB320F2B3A400E148CB /* InterfaceViewController.swift */, 91 | D8976AB520F2B3D900E148CB /* CalculatorButton.swift */, 92 | D8976ABB20F2D3DC00E148CB /* Spring.swift */, 93 | D8976AB720F2D38E00E148CB /* FlashlightButton.swift */, 94 | D8976AB920F2D3B500E148CB /* Rubberbanding.swift */, 95 | D8976ABD20F2D3FA00E148CB /* Acceleration.swift */, 96 | D8976ABF20F2D42200E148CB /* Momentum.swift */, 97 | D8976AC120F2D44C00E148CB /* Pip.swift */, 98 | D8976AC520F2D48800E148CB /* Rotation.swift */, 99 | D8409D0B20FC010B00C7DCD2 /* GradientView.swift */, 100 | D806B89120F82A3700740219 /* UIViewExtensions.swift */, 101 | D806B88F20F8275600740219 /* UIColorExtensions.swift */, 102 | D8409D0920FBDA8100C7DCD2 /* CGPointExtensions.swift */, 103 | E70E61782129959E00633473 /* SwiftExtensions.swift */, 104 | D8757E7520F124BD00D7EB4E /* Main.storyboard */, 105 | D8757E7820F124BF00D7EB4E /* Assets.xcassets */, 106 | D8757E7A20F124BF00D7EB4E /* LaunchScreen.storyboard */, 107 | D8757E7D20F124BF00D7EB4E /* Info.plist */, 108 | ); 109 | path = FluidInterfaces; 110 | sourceTree = ""; 111 | }; 112 | /* End PBXGroup section */ 113 | 114 | /* Begin PBXNativeTarget section */ 115 | D8757E6D20F124BD00D7EB4E /* FluidInterfaces */ = { 116 | isa = PBXNativeTarget; 117 | buildConfigurationList = D8757E8020F124BF00D7EB4E /* Build configuration list for PBXNativeTarget "FluidInterfaces" */; 118 | buildPhases = ( 119 | D8757E6A20F124BD00D7EB4E /* Sources */, 120 | D8757E6B20F124BD00D7EB4E /* Frameworks */, 121 | D8757E6C20F124BD00D7EB4E /* Resources */, 122 | ); 123 | buildRules = ( 124 | ); 125 | dependencies = ( 126 | ); 127 | name = FluidInterfaces; 128 | productName = FluidInterfaces; 129 | productReference = D8757E6E20F124BD00D7EB4E /* FluidInterfaces.app */; 130 | productType = "com.apple.product-type.application"; 131 | }; 132 | /* End PBXNativeTarget section */ 133 | 134 | /* Begin PBXProject section */ 135 | D8757E6620F124BD00D7EB4E /* Project object */ = { 136 | isa = PBXProject; 137 | attributes = { 138 | LastSwiftUpdateCheck = 1000; 139 | LastUpgradeCheck = 1000; 140 | ORGANIZATIONNAME = "Nathan Gitter"; 141 | TargetAttributes = { 142 | D8757E6D20F124BD00D7EB4E = { 143 | CreatedOnToolsVersion = 10.0; 144 | }; 145 | }; 146 | }; 147 | buildConfigurationList = D8757E6920F124BD00D7EB4E /* Build configuration list for PBXProject "FluidInterfaces" */; 148 | compatibilityVersion = "Xcode 9.3"; 149 | developmentRegion = en; 150 | hasScannedForEncodings = 0; 151 | knownRegions = ( 152 | en, 153 | Base, 154 | ); 155 | mainGroup = D8757E6520F124BD00D7EB4E; 156 | productRefGroup = D8757E6F20F124BD00D7EB4E /* Products */; 157 | projectDirPath = ""; 158 | projectRoot = ""; 159 | targets = ( 160 | D8757E6D20F124BD00D7EB4E /* FluidInterfaces */, 161 | ); 162 | }; 163 | /* End PBXProject section */ 164 | 165 | /* Begin PBXResourcesBuildPhase section */ 166 | D8757E6C20F124BD00D7EB4E /* Resources */ = { 167 | isa = PBXResourcesBuildPhase; 168 | buildActionMask = 2147483647; 169 | files = ( 170 | D8757E7C20F124BF00D7EB4E /* LaunchScreen.storyboard in Resources */, 171 | D8757E7920F124BF00D7EB4E /* Assets.xcassets in Resources */, 172 | D8757E7720F124BD00D7EB4E /* Main.storyboard in Resources */, 173 | ); 174 | runOnlyForDeploymentPostprocessing = 0; 175 | }; 176 | /* End PBXResourcesBuildPhase section */ 177 | 178 | /* Begin PBXSourcesBuildPhase section */ 179 | D8757E6A20F124BD00D7EB4E /* Sources */ = { 180 | isa = PBXSourcesBuildPhase; 181 | buildActionMask = 2147483647; 182 | files = ( 183 | D8976AB420F2B3A400E148CB /* InterfaceViewController.swift in Sources */, 184 | D806B89220F82A3700740219 /* UIViewExtensions.swift in Sources */, 185 | D806B89020F8275600740219 /* UIColorExtensions.swift in Sources */, 186 | D8976ABC20F2D3DC00E148CB /* Spring.swift in Sources */, 187 | D8757E7420F124BD00D7EB4E /* MenuViewController.swift in Sources */, 188 | D8409D0C20FC010B00C7DCD2 /* GradientView.swift in Sources */, 189 | D8976AB820F2D38E00E148CB /* FlashlightButton.swift in Sources */, 190 | D8409D0A20FBDA8100C7DCD2 /* CGPointExtensions.swift in Sources */, 191 | D8757E7220F124BD00D7EB4E /* AppDelegate.swift in Sources */, 192 | D8976ABE20F2D3FA00E148CB /* Acceleration.swift in Sources */, 193 | D8976AC020F2D42200E148CB /* Momentum.swift in Sources */, 194 | D8976AC620F2D48800E148CB /* Rotation.swift in Sources */, 195 | D8976AB220F2B2FA00E148CB /* Interface.swift in Sources */, 196 | D8976AB620F2B3D900E148CB /* CalculatorButton.swift in Sources */, 197 | E70E61792129959E00633473 /* SwiftExtensions.swift in Sources */, 198 | D8976AC220F2D44C00E148CB /* Pip.swift in Sources */, 199 | D8976ABA20F2D3B500E148CB /* Rubberbanding.swift in Sources */, 200 | ); 201 | runOnlyForDeploymentPostprocessing = 0; 202 | }; 203 | /* End PBXSourcesBuildPhase section */ 204 | 205 | /* Begin PBXVariantGroup section */ 206 | D8757E7520F124BD00D7EB4E /* Main.storyboard */ = { 207 | isa = PBXVariantGroup; 208 | children = ( 209 | D8757E7620F124BD00D7EB4E /* Base */, 210 | ); 211 | name = Main.storyboard; 212 | sourceTree = ""; 213 | }; 214 | D8757E7A20F124BF00D7EB4E /* LaunchScreen.storyboard */ = { 215 | isa = PBXVariantGroup; 216 | children = ( 217 | D8757E7B20F124BF00D7EB4E /* Base */, 218 | ); 219 | name = LaunchScreen.storyboard; 220 | sourceTree = ""; 221 | }; 222 | /* End PBXVariantGroup section */ 223 | 224 | /* Begin XCBuildConfiguration section */ 225 | D8757E7E20F124BF00D7EB4E /* Debug */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | CLANG_ANALYZER_NONNULL = YES; 230 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 231 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 232 | CLANG_CXX_LIBRARY = "libc++"; 233 | CLANG_ENABLE_MODULES = YES; 234 | CLANG_ENABLE_OBJC_ARC = YES; 235 | CLANG_ENABLE_OBJC_WEAK = YES; 236 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 237 | CLANG_WARN_BOOL_CONVERSION = YES; 238 | CLANG_WARN_COMMA = YES; 239 | CLANG_WARN_CONSTANT_CONVERSION = YES; 240 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 241 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 242 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 243 | CLANG_WARN_EMPTY_BODY = YES; 244 | CLANG_WARN_ENUM_CONVERSION = YES; 245 | CLANG_WARN_INFINITE_RECURSION = YES; 246 | CLANG_WARN_INT_CONVERSION = YES; 247 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 248 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 249 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 250 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 251 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 252 | CLANG_WARN_STRICT_PROTOTYPES = YES; 253 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 254 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 255 | CLANG_WARN_UNREACHABLE_CODE = YES; 256 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 257 | CODE_SIGN_IDENTITY = "iPhone Developer"; 258 | COPY_PHASE_STRIP = NO; 259 | DEBUG_INFORMATION_FORMAT = dwarf; 260 | ENABLE_STRICT_OBJC_MSGSEND = YES; 261 | ENABLE_TESTABILITY = YES; 262 | GCC_C_LANGUAGE_STANDARD = gnu11; 263 | GCC_DYNAMIC_NO_PIC = NO; 264 | GCC_NO_COMMON_BLOCKS = YES; 265 | GCC_OPTIMIZATION_LEVEL = 0; 266 | GCC_PREPROCESSOR_DEFINITIONS = ( 267 | "DEBUG=1", 268 | "$(inherited)", 269 | ); 270 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 271 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 272 | GCC_WARN_UNDECLARED_SELECTOR = YES; 273 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 274 | GCC_WARN_UNUSED_FUNCTION = YES; 275 | GCC_WARN_UNUSED_VARIABLE = YES; 276 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 277 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 278 | ONLY_ACTIVE_ARCH = YES; 279 | SDKROOT = iphoneos; 280 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 281 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 282 | }; 283 | name = Debug; 284 | }; 285 | D8757E7F20F124BF00D7EB4E /* Release */ = { 286 | isa = XCBuildConfiguration; 287 | buildSettings = { 288 | ALWAYS_SEARCH_USER_PATHS = NO; 289 | CLANG_ANALYZER_NONNULL = YES; 290 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 291 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 292 | CLANG_CXX_LIBRARY = "libc++"; 293 | CLANG_ENABLE_MODULES = YES; 294 | CLANG_ENABLE_OBJC_ARC = YES; 295 | CLANG_ENABLE_OBJC_WEAK = YES; 296 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 297 | CLANG_WARN_BOOL_CONVERSION = YES; 298 | CLANG_WARN_COMMA = YES; 299 | CLANG_WARN_CONSTANT_CONVERSION = YES; 300 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 301 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 302 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 303 | CLANG_WARN_EMPTY_BODY = YES; 304 | CLANG_WARN_ENUM_CONVERSION = YES; 305 | CLANG_WARN_INFINITE_RECURSION = YES; 306 | CLANG_WARN_INT_CONVERSION = YES; 307 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 308 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 309 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 310 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 311 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 312 | CLANG_WARN_STRICT_PROTOTYPES = YES; 313 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 314 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 315 | CLANG_WARN_UNREACHABLE_CODE = YES; 316 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 317 | CODE_SIGN_IDENTITY = "iPhone Developer"; 318 | COPY_PHASE_STRIP = NO; 319 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 320 | ENABLE_NS_ASSERTIONS = NO; 321 | ENABLE_STRICT_OBJC_MSGSEND = YES; 322 | GCC_C_LANGUAGE_STANDARD = gnu11; 323 | GCC_NO_COMMON_BLOCKS = YES; 324 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 325 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 326 | GCC_WARN_UNDECLARED_SELECTOR = YES; 327 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 328 | GCC_WARN_UNUSED_FUNCTION = YES; 329 | GCC_WARN_UNUSED_VARIABLE = YES; 330 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 331 | MTL_ENABLE_DEBUG_INFO = NO; 332 | SDKROOT = iphoneos; 333 | SWIFT_COMPILATION_MODE = wholemodule; 334 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 335 | VALIDATE_PRODUCT = YES; 336 | }; 337 | name = Release; 338 | }; 339 | D8757E8120F124BF00D7EB4E /* Debug */ = { 340 | isa = XCBuildConfiguration; 341 | buildSettings = { 342 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 343 | CODE_SIGN_STYLE = Automatic; 344 | DEVELOPMENT_TEAM = PW5ET5HNB2; 345 | INFOPLIST_FILE = FluidInterfaces/Info.plist; 346 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 347 | LD_RUNPATH_SEARCH_PATHS = ( 348 | "$(inherited)", 349 | "@executable_path/Frameworks", 350 | ); 351 | PRODUCT_BUNDLE_IDENTIFIER = nathangitter.FluidInterfaces; 352 | PRODUCT_NAME = "$(TARGET_NAME)"; 353 | SWIFT_VERSION = 4.2; 354 | TARGETED_DEVICE_FAMILY = "1,2"; 355 | }; 356 | name = Debug; 357 | }; 358 | D8757E8220F124BF00D7EB4E /* Release */ = { 359 | isa = XCBuildConfiguration; 360 | buildSettings = { 361 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 362 | CODE_SIGN_STYLE = Automatic; 363 | DEVELOPMENT_TEAM = PW5ET5HNB2; 364 | INFOPLIST_FILE = FluidInterfaces/Info.plist; 365 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 366 | LD_RUNPATH_SEARCH_PATHS = ( 367 | "$(inherited)", 368 | "@executable_path/Frameworks", 369 | ); 370 | PRODUCT_BUNDLE_IDENTIFIER = nathangitter.FluidInterfaces; 371 | PRODUCT_NAME = "$(TARGET_NAME)"; 372 | SWIFT_VERSION = 4.2; 373 | TARGETED_DEVICE_FAMILY = "1,2"; 374 | }; 375 | name = Release; 376 | }; 377 | /* End XCBuildConfiguration section */ 378 | 379 | /* Begin XCConfigurationList section */ 380 | D8757E6920F124BD00D7EB4E /* Build configuration list for PBXProject "FluidInterfaces" */ = { 381 | isa = XCConfigurationList; 382 | buildConfigurations = ( 383 | D8757E7E20F124BF00D7EB4E /* Debug */, 384 | D8757E7F20F124BF00D7EB4E /* Release */, 385 | ); 386 | defaultConfigurationIsVisible = 0; 387 | defaultConfigurationName = Release; 388 | }; 389 | D8757E8020F124BF00D7EB4E /* Build configuration list for PBXNativeTarget "FluidInterfaces" */ = { 390 | isa = XCConfigurationList; 391 | buildConfigurations = ( 392 | D8757E8120F124BF00D7EB4E /* Debug */, 393 | D8757E8220F124BF00D7EB4E /* Release */, 394 | ); 395 | defaultConfigurationIsVisible = 0; 396 | defaultConfigurationName = Release; 397 | }; 398 | /* End XCConfigurationList section */ 399 | }; 400 | rootObject = D8757E6620F124BD00D7EB4E /* Project object */; 401 | } 402 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Acceleration.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Acceleration.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/8/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class AccelerationInterfaceViewController: InterfaceViewController { 12 | 13 | private lazy var pauseLabel: UILabel = { 14 | let label = UILabel() 15 | label.text = "PAUSED" 16 | label.font = UIFont.systemFont(ofSize: 16, weight: .bold) 17 | label.textColor = .white 18 | label.textAlignment = .center 19 | label.translatesAutoresizingMaskIntoConstraints = false 20 | label.alpha = 0 21 | return label 22 | }() 23 | 24 | private lazy var accelerationView: GradientView = { 25 | let view = GradientView() 26 | view.topColor = UIColor(hex: 0x64FF8F) 27 | view.bottomColor = UIColor(hex: 0x51FFEA) 28 | return view 29 | }() 30 | 31 | private let panRecognizer = UIPanGestureRecognizer() 32 | 33 | private let feedbackGenerator = UIImpactFeedbackGenerator(style: .light) 34 | 35 | private let verticalOffset: CGFloat = 180 36 | 37 | override func viewDidLoad() { 38 | super.viewDidLoad() 39 | 40 | view.addSubview(pauseLabel) 41 | pauseLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true 42 | pauseLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 40).isActive = true 43 | 44 | view.addSubview(accelerationView) 45 | accelerationView.center(in: view, offset: UIOffset(horizontal: 0, vertical: verticalOffset)) 46 | accelerationView.widthAnchor.constraint(equalToConstant: 160).isActive = true 47 | accelerationView.heightAnchor.constraint(equalToConstant: 160).isActive = true 48 | 49 | panRecognizer.addTarget(self, action: #selector(panned)) 50 | accelerationView.addGestureRecognizer(panRecognizer) 51 | 52 | } 53 | 54 | private var originalTouchPoint: CGPoint = .zero 55 | 56 | @objc private func panned(recognizer: UIPanGestureRecognizer) { 57 | let touchPoint = recognizer.location(in: view) 58 | let velocity = recognizer.velocity(in: view) 59 | switch recognizer.state { 60 | case .began: 61 | originalTouchPoint = touchPoint 62 | case .changed: 63 | let offset: CGFloat = { 64 | let offset = touchPoint.y - originalTouchPoint.y 65 | if offset > 0 { 66 | return pow(offset, 0.7) 67 | } else if offset < -verticalOffset * 2 { 68 | return -verticalOffset * 2 - pow(-(offset + verticalOffset * 2), 0.7) 69 | } 70 | return offset 71 | }() 72 | accelerationView.transform = CGAffineTransform(translationX: 0, y: offset) 73 | trackPause(velocity: velocity.y, offset: offset) 74 | case .ended, .cancelled: 75 | let timingParameters = UISpringTimingParameters(damping: 0.8, response: 0.3) 76 | let animator = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters) 77 | animator.addAnimations { 78 | self.accelerationView.transform = .identity 79 | self.pauseLabel.alpha = 0 80 | } 81 | animator.isInterruptible = true 82 | animator.startAnimation() 83 | hasPaused = false 84 | default: break 85 | } 86 | } 87 | 88 | /// The number of past velocities to track. 89 | private let numberOfVelocities = 7 90 | 91 | /// The array of past velocities. 92 | private var velocities = [CGFloat]() 93 | 94 | /// Whether the view is considered paused. 95 | private var hasPaused = false 96 | 97 | /// Tracks the most recent velocity values, and determines whether the change is great enough to be pasued. 98 | /// After calling this function, the result can be checked in the `hasPaused` property. 99 | private func trackPause(velocity: CGFloat, offset: CGFloat) { 100 | 101 | // if the motion is paused, we are done 102 | if hasPaused { return } 103 | 104 | // update the array of most recent velocities 105 | if velocities.count < numberOfVelocities { 106 | velocities.append(velocity) 107 | return 108 | } else { 109 | velocities = Array(velocities.dropFirst()) 110 | velocities.append(velocity) 111 | } 112 | 113 | // enforce minimum velocity and offset 114 | if abs(velocity) > 100 || abs(offset) < 50 { return } 115 | 116 | guard let firstRecordedVelocity = velocities.first else { return } 117 | 118 | // if the majority of the velocity has been lost recetly, we consider the motion to be paused 119 | if abs(firstRecordedVelocity - velocity) / abs(firstRecordedVelocity) > 0.9 { 120 | pauseLabel.alpha = 1 121 | feedbackGenerator.impactOccurred() 122 | hasPaused = true 123 | velocities.removeAll() 124 | } 125 | 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/7/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | } 17 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "60x60", 35 | "idiom" : "iphone", 36 | "filename" : "icon120.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "60x60", 41 | "idiom" : "iphone", 42 | "filename" : "icon180.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "idiom" : "ipad", 47 | "size" : "20x20", 48 | "scale" : "1x" 49 | }, 50 | { 51 | "idiom" : "ipad", 52 | "size" : "20x20", 53 | "scale" : "2x" 54 | }, 55 | { 56 | "idiom" : "ipad", 57 | "size" : "29x29", 58 | "scale" : "1x" 59 | }, 60 | { 61 | "idiom" : "ipad", 62 | "size" : "29x29", 63 | "scale" : "2x" 64 | }, 65 | { 66 | "idiom" : "ipad", 67 | "size" : "40x40", 68 | "scale" : "1x" 69 | }, 70 | { 71 | "idiom" : "ipad", 72 | "size" : "40x40", 73 | "scale" : "2x" 74 | }, 75 | { 76 | "idiom" : "ipad", 77 | "size" : "76x76", 78 | "scale" : "1x" 79 | }, 80 | { 81 | "size" : "76x76", 82 | "idiom" : "ipad", 83 | "filename" : "icon152.png", 84 | "scale" : "2x" 85 | }, 86 | { 87 | "size" : "83.5x83.5", 88 | "idiom" : "ipad", 89 | "filename" : "icon167.png", 90 | "scale" : "2x" 91 | }, 92 | { 93 | "size" : "1024x1024", 94 | "idiom" : "ios-marketing", 95 | "filename" : "icon.png", 96 | "scale" : "1x" 97 | } 98 | ], 99 | "info" : { 100 | "version" : 1, 101 | "author" : "xcode" 102 | } 103 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/icon.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/icon120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/icon120.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/icon152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/icon152.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/icon167.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/icon167.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/icon180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/AppIcon.appiconset/icon180.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/chevron.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "chevron.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "template" 14 | } 15 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/chevron.imageset/chevron.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/chevron.imageset/chevron.pdf -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/flashlight_off.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "flashlight_off.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "template" 14 | } 15 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/flashlight_off.imageset/flashlight_off.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/flashlight_off.imageset/flashlight_off.pdf -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/flashlight_on.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "flashlight_on.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | }, 12 | "properties" : { 13 | "template-rendering-intent" : "template" 14 | } 15 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/flashlight_on.imageset/flashlight_on.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/flashlight_on.imageset/flashlight_on.pdf -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_acceleration.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_acceleration.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_acceleration.imageset/icon_acceleration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_acceleration.imageset/icon_acceleration.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_calc.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_calc.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_calc.imageset/icon_calc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_calc.imageset/icon_calc.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_flash.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_flash.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_flash.imageset/icon_flash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_flash.imageset/icon_flash.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_momentum.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_momentum.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_momentum.imageset/icon_momentum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_momentum.imageset/icon_momentum.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_pip.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_pip.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_pip.imageset/icon_pip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_pip.imageset/icon_pip.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_rotation.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_rotation.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_rotation.imageset/icon_rotation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_rotation.imageset/icon_rotation.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_rubber.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_rubber.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_rubber.imageset/icon_rubber.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_rubber.imageset/icon_rubber.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_spring.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x" 10 | }, 11 | { 12 | "idiom" : "universal", 13 | "filename" : "icon_spring.png", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_spring.imageset/icon_spring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/FluidInterfaces/FluidInterfaces/Assets.xcassets/icon_spring.imageset/icon_spring.png -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/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 | 29 | 30 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/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 | 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 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/CGPointExtensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CGPointExtensions.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/15/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import CoreGraphics 10 | 11 | extension CGPoint { 12 | 13 | /// Calculates the distance between two points in 2D space. 14 | /// + returns: The distance from this point to the given point. 15 | func distance(to point: CGPoint) -> CGFloat { 16 | return sqrt(pow(point.x - self.x, 2) + pow(point.y - self.y, 2)) 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/CalculatorButton.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CalculatorButton.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/8/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class CalculatorButtonInterfaceViewController: InterfaceViewController { 12 | 13 | private lazy var calculatorButton: CalculatorButton = { 14 | let button = CalculatorButton() 15 | button.value = 9 16 | return button 17 | }() 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | 22 | view.addSubview(calculatorButton) 23 | calculatorButton.center(in: view) 24 | 25 | } 26 | 27 | } 28 | 29 | class CalculatorButton: UIControl { 30 | 31 | /// The value to display on the button. 32 | public var value: Int = 0 { 33 | didSet { 34 | label.text = "\(value)" 35 | } 36 | } 37 | 38 | private var label: UILabel = { 39 | let label = UILabel() 40 | label.font = UIFont.systemFont(ofSize: 36, weight: .regular) 41 | label.textColor = .white 42 | label.textAlignment = .center 43 | return label 44 | }() 45 | 46 | private var animator = UIViewPropertyAnimator() 47 | 48 | private let normalColor = UIColor(hex: 0x333333) 49 | private let highlightedColor = UIColor(hex: 0x737373) 50 | 51 | override init(frame: CGRect) { 52 | super.init(frame: frame) 53 | sharedInit() 54 | } 55 | 56 | required init?(coder aDecoder: NSCoder) { 57 | super.init(coder: aDecoder) 58 | sharedInit() 59 | } 60 | 61 | private func sharedInit() { 62 | 63 | backgroundColor = normalColor 64 | 65 | addTarget(self, action: #selector(touchDown), for: [.touchDown, .touchDragEnter]) 66 | addTarget(self, action: #selector(touchUp), for: [.touchUpInside, .touchDragExit, .touchCancel]) 67 | 68 | addSubview(label) 69 | label.center(in: self) 70 | 71 | } 72 | 73 | override var intrinsicContentSize: CGSize { 74 | return CGSize(width: 75, height: 75) 75 | } 76 | 77 | override func layoutSubviews() { 78 | super.layoutSubviews() 79 | layer.cornerRadius = bounds.width / 2 80 | } 81 | 82 | @objc private func touchDown() { 83 | animator.stopAnimation(true) 84 | backgroundColor = highlightedColor 85 | } 86 | 87 | @objc private func touchUp() { 88 | animator = UIViewPropertyAnimator(duration: 0.5, curve: .easeOut, animations: { 89 | self.backgroundColor = self.normalColor 90 | }) 91 | animator.startAnimation() 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/FlashlightButton.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FlashlightButton.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/8/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class FlashlightButtonInterfaceViewController: InterfaceViewController { 12 | 13 | private let flashlightButton = FlashlightButton() 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | 18 | view.addSubview(flashlightButton) 19 | flashlightButton.center(in: view) 20 | 21 | } 22 | 23 | } 24 | 25 | class FlashlightButton: UIControl { 26 | 27 | private enum ForceState { 28 | 29 | /// The button is ready to be activiated. Default state. 30 | case reset 31 | 32 | /// The button has been pressed with enough force. 33 | case activated 34 | 35 | /// The button has recently switched on/off. 36 | case confirmed 37 | 38 | } 39 | 40 | private lazy var imageView: UIImageView = { 41 | let imageView = UIImageView() 42 | imageView.image = offImage 43 | imageView.tintColor = .white 44 | return imageView 45 | }() 46 | 47 | /// Whether the button is on or off. 48 | private var isOn = false 49 | 50 | /// The current state of the force press. 51 | private var forceState: ForceState = .reset 52 | 53 | /// Whether the touch has exited the bounds of the button. 54 | /// This is used to cancel touches that move outisde of its bounds. 55 | private var touchExited = false 56 | 57 | private let activationFeedbackGenerator = UIImpactFeedbackGenerator(style: .light) 58 | private let confirmationFeedbackGenerator = UIImpactFeedbackGenerator(style: .medium) 59 | 60 | private let minWidth: CGFloat = 50 61 | private let maxWidth: CGFloat = 92 62 | 63 | private let offColor = UIColor(white: 0.2, alpha: 1) 64 | private let onColor = UIColor(white: 0.95, alpha: 1) 65 | 66 | private let onImage = #imageLiteral(resourceName: "flashlight_on") 67 | private let offImage = #imageLiteral(resourceName: "flashlight_off") 68 | 69 | private let activationForce: CGFloat = 0.5 70 | private let confirmationForce: CGFloat = 0.49 71 | private let resetForce: CGFloat = 0.4 72 | 73 | override init(frame: CGRect) { 74 | super.init(frame: frame) 75 | sharedInit() 76 | } 77 | 78 | required init?(coder aDecoder: NSCoder) { 79 | super.init(coder: aDecoder) 80 | sharedInit() 81 | } 82 | 83 | private func sharedInit() { 84 | 85 | backgroundColor = offColor 86 | 87 | addSubview(imageView) 88 | imageView.pin(to: self) 89 | 90 | } 91 | 92 | override var intrinsicContentSize: CGSize { 93 | return CGSize(width: minWidth, height: minWidth) 94 | } 95 | 96 | override func layoutSubviews() { 97 | super.layoutSubviews() 98 | layer.cornerRadius = bounds.width / 2 99 | } 100 | 101 | override func touchesBegan(_ touches: Set, with event: UIEvent?) { 102 | super.touchesBegan(touches, with: event) 103 | touchExited = false 104 | touchMoved(touch: touches.first) 105 | } 106 | 107 | override func touchesMoved(_ touches: Set, with event: UIEvent?) { 108 | super.touchesMoved(touches, with: event) 109 | touchMoved(touch: touches.first) 110 | } 111 | 112 | override func touchesEnded(_ touches: Set, with event: UIEvent?) { 113 | super.touchesEnded(touches, with: event) 114 | touchEnded(touch: touches.first) 115 | } 116 | 117 | override func touchesCancelled(_ touches: Set, with event: UIEvent?) { 118 | super.touchesCancelled(touches, with: event) 119 | touchEnded(touch: touches.first) 120 | } 121 | 122 | private func touchMoved(touch: UITouch?) { 123 | 124 | guard let touch = touch else { return } 125 | guard !touchExited else { return } 126 | 127 | let cancelDistance: CGFloat = minWidth / 2 + 20 128 | guard touch.location(in: self).distance(to: CGPoint(x: bounds.midX, y: bounds.midY)) < cancelDistance else { 129 | // the touch has moved outside of the bounds of the button 130 | touchExited = true 131 | forceState = .reset 132 | animateToRest() 133 | return 134 | } 135 | 136 | let force = touch.force / touch.maximumPossibleForce 137 | let scale = 1 + (maxWidth / minWidth - 1) * force 138 | 139 | // update the button's size and color 140 | transform = CGAffineTransform(scaleX: scale, y: scale) 141 | if !isOn { backgroundColor = UIColor(white: 0.2 - force * 0.2, alpha: 1) } 142 | 143 | switch forceState { 144 | case .reset: 145 | if force >= activationForce { 146 | forceState = .activated 147 | activationFeedbackGenerator.impactOccurred() 148 | } 149 | case .activated: 150 | if force <= confirmationForce { 151 | forceState = .confirmed 152 | activate() 153 | } 154 | case .confirmed: 155 | if force <= resetForce { 156 | forceState = .reset 157 | } 158 | } 159 | 160 | } 161 | 162 | private func touchEnded(touch: UITouch?) { 163 | guard !touchExited else { return } 164 | if forceState == .activated { activate() } 165 | forceState = .reset 166 | animateToRest() 167 | } 168 | 169 | private func activate() { 170 | isOn.toggle() 171 | imageView.image = isOn ? onImage : offImage 172 | imageView.tintColor = isOn ? .black : .white 173 | backgroundColor = isOn ? onColor : offColor 174 | confirmationFeedbackGenerator.impactOccurred() 175 | } 176 | 177 | private func animateToRest() { 178 | let timingParameters = UISpringTimingParameters(damping: 0.4, response: 0.2) 179 | let animator = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters) 180 | animator.addAnimations { 181 | self.transform = CGAffineTransform(scaleX: 1, y: 1) 182 | self.backgroundColor = self.isOn ? self.onColor : self.offColor 183 | } 184 | animator.isInterruptible = true 185 | animator.startAnimation() 186 | } 187 | 188 | } 189 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/GradientView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GradientView.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/15/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class GradientView: UIView { 12 | 13 | public var topColor: UIColor = .white { 14 | didSet { 15 | updateGradientColors() 16 | } 17 | } 18 | 19 | public var bottomColor: UIColor = .black { 20 | didSet { 21 | updateGradientColors() 22 | } 23 | } 24 | 25 | /// The corner radius of the view. 26 | /// If no value is provided, the default is 20% of the view's width. 27 | public var cornerRadius: CGFloat? { 28 | didSet { 29 | layoutSubviews() 30 | } 31 | } 32 | 33 | private lazy var gradientLayer: CAGradientLayer = { 34 | let gradientLayer = CAGradientLayer() 35 | gradientLayer.colors = [topColor.cgColor, bottomColor.cgColor] 36 | gradientLayer.startPoint = CGPoint(x: 0, y: 0) 37 | gradientLayer.endPoint = CGPoint(x: 0, y: 1) 38 | return gradientLayer 39 | }() 40 | 41 | override init(frame: CGRect) { 42 | super.init(frame: frame) 43 | sharedInit() 44 | } 45 | 46 | required init?(coder aDecoder: NSCoder) { 47 | super.init(coder: aDecoder) 48 | sharedInit() 49 | } 50 | 51 | private func sharedInit() { 52 | layer.addSublayer(gradientLayer) 53 | } 54 | 55 | override func layoutSubviews() { 56 | super.layoutSubviews() 57 | gradientLayer.frame = bounds 58 | let maskLayer = CAShapeLayer() 59 | maskLayer.path = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius ?? bounds.width * 0.2).cgPath 60 | layer.mask = maskLayer 61 | } 62 | 63 | private func updateGradientColors() { 64 | gradientLayer.colors = [topColor.cgColor, bottomColor.cgColor] 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Fluid Interfaces 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Interface.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Interface.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/8/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | struct Interface { 12 | var name: String 13 | var icon: UIImage 14 | var color: UIColor 15 | var type: InterfaceViewController.Type 16 | } 17 | 18 | extension Interface { 19 | 20 | public static var all: [Interface] { 21 | return [ 22 | Interface(name: "Calculator button", icon: #imageLiteral(resourceName: "icon_calc"), color: UIColor(hex: 0x999999), type: CalculatorButtonInterfaceViewController.self), 23 | Interface(name: "Spring animations", icon: #imageLiteral(resourceName: "icon_spring"), color: UIColor(hex: 0x64CCF7), type: SpringInterfaceViewController.self), 24 | Interface(name: "Flashlight button", icon: #imageLiteral(resourceName: "icon_flash"), color: UIColor(hex: 0xEDEDED), type: FlashlightButtonInterfaceViewController.self), 25 | Interface(name: "Rubberbanding", icon: #imageLiteral(resourceName: "icon_rubber"), color: UIColor(hex: 0xFF5B50), type: RubberbandingInterfaceViewController.self), 26 | Interface(name: "Acceleration pausing", icon: #imageLiteral(resourceName: "icon_acceleration"), color: UIColor(hex: 0x64FF8F), type: AccelerationInterfaceViewController.self), 27 | Interface(name: "Rewarding momentum", icon: #imageLiteral(resourceName: "icon_momentum"), color: UIColor(hex: 0x73B2FF), type: MomentumInterfaceViewController.self), 28 | Interface(name: "FaceTime PiP", icon: #imageLiteral(resourceName: "icon_pip"), color: UIColor(hex: 0xF2F23A), type: PipInterfaceViewController.self), 29 | Interface(name: "Rotation", icon: #imageLiteral(resourceName: "icon_rotation"), color: UIColor(hex: 0xFF28A5), type: RotationInterfaceViewController.self), 30 | ] 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/InterfaceViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InterfaceViewController.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/8/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /// Base class for all interface view controllers. 12 | class InterfaceViewController: UIViewController { 13 | 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | 17 | view.backgroundColor = UIColor(white: 0.05, alpha: 1) // reduces screen tearing on iPhone X 18 | navigationItem.largeTitleDisplayMode = .never 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/MenuViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MenuViewController.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/7/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MenuViewController: UIViewController { 12 | 13 | private let interfaces = Interface.all 14 | 15 | @IBOutlet private weak var collectionView: UICollectionView! 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | 20 | view.backgroundColor = UIColor(white: 0.05, alpha: 1) 21 | 22 | } 23 | 24 | override func viewWillAppear(_ animated: Bool) { 25 | super.viewWillAppear(animated) 26 | 27 | collectionView.visibleCells.forEach { 28 | $0.isHighlighted = false 29 | } 30 | 31 | } 32 | 33 | } 34 | 35 | extension MenuViewController: UICollectionViewDelegate { 36 | 37 | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 38 | collectionView.cellForItem(at: indexPath)?.isHighlighted = true 39 | let interface = interfaces[indexPath.item] 40 | let viewController = interface.type.init() 41 | viewController.title = interface.name 42 | navigationController?.pushViewController(viewController, animated: true) 43 | viewController.navigationController?.navigationBar.tintColor = interface.color 44 | } 45 | 46 | } 47 | 48 | extension MenuViewController: UICollectionViewDataSource { 49 | 50 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 51 | return interfaces.count 52 | } 53 | 54 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 55 | guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: InterfaceCell.identifier, for: indexPath) as? InterfaceCell else { return UICollectionViewCell() } 56 | let interface = interfaces[indexPath.item] 57 | cell.title = interface.name 58 | cell.image = interface.icon 59 | return cell 60 | } 61 | 62 | } 63 | 64 | extension MenuViewController: UICollectionViewDelegateFlowLayout { 65 | 66 | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 67 | return CGSize(width: collectionView.bounds.width, height: 60) 68 | } 69 | 70 | } 71 | 72 | class InterfaceCell: UICollectionViewCell { 73 | 74 | public static let identifier = "interfaceCell" 75 | 76 | public var title = "" { 77 | didSet { 78 | titleLabel.text = title 79 | } 80 | } 81 | 82 | public var image = UIImage() { 83 | didSet { 84 | imageView.image = image 85 | } 86 | } 87 | 88 | @IBOutlet private weak var imageView: UIImageView! 89 | @IBOutlet private weak var titleLabel: UILabel! 90 | 91 | override init(frame: CGRect) { 92 | super.init(frame: frame) 93 | sharedInit() 94 | } 95 | 96 | required init?(coder aDecoder: NSCoder) { 97 | super.init(coder: aDecoder) 98 | sharedInit() 99 | } 100 | 101 | private func sharedInit() { 102 | backgroundColor = UIColor.white.withAlphaComponent(0.1) 103 | } 104 | 105 | override var isHighlighted: Bool { 106 | didSet { 107 | backgroundColor = UIColor.white.withAlphaComponent(isHighlighted ? 0.2 : 0.1) 108 | } 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Momentum.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Momentum.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/8/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import UIKit.UIGestureRecognizerSubclass 11 | 12 | // If I were to do this again, I would probably take the following approach: 13 | // 14 | // 1. Instead of using the `UIViewPropertyAnimator`s `fractionComplete` and `isReversed`, 15 | // I would update the position of the view at any point manually. 16 | // 2. Only use a UIViewPropertyAnimator to "finish" the animation (with or without damping). 17 | // 3. Remove the ability to "catch" the view mid-flight. 18 | // It has a little bit of jank, and with a fast animation doesn't seem that practical. 19 | // (Still should be interruptible and reversible, but with a pan gesture.) 20 | // 4. Add rubberbanding to the top and bottom boundaries of the view. 21 | // 5. Allow the view to have an arbitrary, potentially scrolling view as its content. 22 | 23 | class MomentumInterfaceViewController: InterfaceViewController { 24 | 25 | private lazy var momentumView: GradientView = { 26 | let view = GradientView() 27 | view.translatesAutoresizingMaskIntoConstraints = false 28 | view.backgroundColor = UIColor(white: 0.3, alpha: 1) 29 | view.topColor = UIColor(hex: 0x61A8FF) 30 | view.bottomColor = UIColor(hex: 0x243BD1) 31 | view.cornerRadius = 30 32 | return view 33 | }() 34 | 35 | private lazy var handleView: UIView = { 36 | let view = UIView() 37 | view.translatesAutoresizingMaskIntoConstraints = false 38 | view.backgroundColor = UIColor(white: 1, alpha: 0.5) 39 | view.layer.cornerRadius = 3 40 | return view 41 | }() 42 | 43 | // todo: add an explicit tap recognizer as well 44 | private let panRecognier = InstantPanGestureRecognizer() 45 | 46 | private var animator = UIViewPropertyAnimator() 47 | 48 | // todo: refactor state to use an enum with associated valued 49 | private var isOpen = false 50 | private var animationProgress: CGFloat = 0 51 | 52 | private var closedTransform = CGAffineTransform.identity 53 | 54 | override func viewDidLoad() { 55 | super.viewDidLoad() 56 | 57 | view.addSubview(momentumView) 58 | momentumView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 8).isActive = true 59 | momentumView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -8).isActive = true 60 | momentumView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 80).isActive = true 61 | momentumView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 80).isActive = true 62 | 63 | momentumView.addSubview(handleView) 64 | handleView.topAnchor.constraint(equalTo: momentumView.topAnchor, constant: 10).isActive = true 65 | handleView.widthAnchor.constraint(equalToConstant: 50).isActive = true 66 | handleView.heightAnchor.constraint(equalToConstant: 5).isActive = true 67 | handleView.centerXAnchor.constraint(equalTo: momentumView.centerXAnchor).isActive = true 68 | 69 | closedTransform = CGAffineTransform(translationX: 0, y: view.bounds.height * 0.6) 70 | momentumView.transform = closedTransform 71 | 72 | panRecognier.addTarget(self, action: #selector(panned)) 73 | momentumView.addGestureRecognizer(panRecognier) 74 | 75 | } 76 | 77 | @objc private func panned(recognizer: UIPanGestureRecognizer) { 78 | switch recognizer.state { 79 | case .began: 80 | startAnimationIfNeeded() 81 | animator.pauseAnimation() 82 | animationProgress = animator.fractionComplete 83 | case .changed: 84 | var fraction = -recognizer.translation(in: momentumView).y / closedTransform.ty 85 | if isOpen { fraction *= -1 } 86 | if animator.isReversed { fraction *= -1 } 87 | animator.fractionComplete = fraction + animationProgress 88 | // todo: rubberbanding 89 | case .ended, .cancelled: 90 | let yVelocity = recognizer.velocity(in: momentumView).y 91 | let shouldClose = yVelocity > 0 // todo: should use projection instead 92 | if yVelocity == 0 { 93 | animator.continueAnimation(withTimingParameters: nil, durationFactor: 0) 94 | break 95 | } 96 | if isOpen { 97 | if !shouldClose && !animator.isReversed { animator.isReversed.toggle() } 98 | if shouldClose && animator.isReversed { animator.isReversed.toggle() } 99 | } else { 100 | if shouldClose && !animator.isReversed { animator.isReversed.toggle() } 101 | if !shouldClose && animator.isReversed { animator.isReversed.toggle() } 102 | } 103 | let fractionRemaining = 1 - animator.fractionComplete 104 | let distanceRemaining = fractionRemaining * closedTransform.ty 105 | if distanceRemaining == 0 { 106 | animator.continueAnimation(withTimingParameters: nil, durationFactor: 0) 107 | break 108 | } 109 | let relativeVelocity = min(abs(yVelocity) / distanceRemaining, 30) 110 | let timingParameters = UISpringTimingParameters(damping: 0.8, response: 0.3, initialVelocity: CGVector(dx: relativeVelocity, dy: relativeVelocity)) 111 | let preferredDuration = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters).duration 112 | let durationFactor = CGFloat(preferredDuration / animator.duration) 113 | animator.continueAnimation(withTimingParameters: timingParameters, durationFactor: durationFactor) 114 | default: break 115 | } 116 | } 117 | 118 | private func startAnimationIfNeeded() { 119 | if animator.isRunning { return } 120 | let timingParameters = UISpringTimingParameters(damping: 1, response: 0.4) 121 | animator = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters) 122 | animator.addAnimations { 123 | self.momentumView.transform = self.isOpen ? self.closedTransform : .identity 124 | } 125 | animator.addCompletion { position in 126 | if position == .end { self.isOpen.toggle() } 127 | } 128 | animator.startAnimation() 129 | } 130 | 131 | } 132 | 133 | class InstantPanGestureRecognizer: UIPanGestureRecognizer { 134 | 135 | override func touchesBegan(_ touches: Set, with event: UIEvent) { 136 | super.touchesBegan(touches, with: event) 137 | self.state = .began 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Pip.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Pip.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/8/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class PipInterfaceViewController: InterfaceViewController { 12 | 13 | private lazy var pipView: GradientView = { 14 | let view = GradientView() 15 | view.topColor = UIColor(hex: 0xF2F23A) 16 | view.bottomColor = UIColor(hex: 0xF7A51C) 17 | view.cornerRadius = 16 18 | return view 19 | }() 20 | 21 | private var pipPositionViews = [PipPositionView]() 22 | 23 | private let panRecognizer = UIPanGestureRecognizer() 24 | 25 | private var pipPositions: [CGPoint] { 26 | return pipPositionViews.map { $0.center } 27 | } 28 | 29 | private let pipWidth: CGFloat = 86 30 | private let pipHeight: CGFloat = 130 31 | 32 | private let horizontalSpacing: CGFloat = 23 33 | private let verticalSpacing: CGFloat = 25 34 | 35 | override func viewDidLoad() { 36 | super.viewDidLoad() 37 | 38 | let topLeftView = addPipPositionView() 39 | topLeftView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: horizontalSpacing).isActive = true 40 | topLeftView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: verticalSpacing).isActive = true 41 | 42 | let topRightView = addPipPositionView() 43 | topRightView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -horizontalSpacing).isActive = true 44 | topRightView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: verticalSpacing).isActive = true 45 | 46 | let bottomLeftView = addPipPositionView() 47 | bottomLeftView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: horizontalSpacing).isActive = true 48 | bottomLeftView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -verticalSpacing).isActive = true 49 | 50 | let bottomRightView = addPipPositionView() 51 | bottomRightView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -horizontalSpacing).isActive = true 52 | bottomRightView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -verticalSpacing).isActive = true 53 | 54 | view.addSubview(pipView) 55 | pipView.translatesAutoresizingMaskIntoConstraints = false 56 | pipView.widthAnchor.constraint(equalToConstant: pipWidth).isActive = true 57 | pipView.heightAnchor.constraint(equalToConstant: pipHeight).isActive = true 58 | 59 | panRecognizer.addTarget(self, action: #selector(pipPanned(recognizer:))) 60 | pipView.addGestureRecognizer(panRecognizer) 61 | 62 | } 63 | 64 | override func viewDidLayoutSubviews() { 65 | super.viewDidLayoutSubviews() 66 | pipView.center = pipPositions.last ?? .zero 67 | } 68 | 69 | private func addPipPositionView() -> PipPositionView { 70 | let view = PipPositionView() 71 | self.view.addSubview(view) 72 | pipPositionViews.append(view) 73 | view.translatesAutoresizingMaskIntoConstraints = false 74 | view.widthAnchor.constraint(equalToConstant: pipWidth).isActive = true 75 | view.heightAnchor.constraint(equalToConstant: pipHeight).isActive = true 76 | return view 77 | } 78 | 79 | private var initialOffset: CGPoint = .zero 80 | 81 | @objc private func pipPanned(recognizer: UIPanGestureRecognizer) { 82 | let touchPoint = recognizer.location(in: view) 83 | switch recognizer.state { 84 | case .began: 85 | initialOffset = CGPoint(x: touchPoint.x - pipView.center.x, y: touchPoint.y - pipView.center.y) 86 | case .changed: 87 | pipView.center = CGPoint(x: touchPoint.x - initialOffset.x, y: touchPoint.y - initialOffset.y) 88 | case .ended, .cancelled: 89 | let decelerationRate = UIScrollView.DecelerationRate.normal.rawValue 90 | let velocity = recognizer.velocity(in: view) 91 | let projectedPosition = CGPoint( 92 | x: pipView.center.x + project(initialVelocity: velocity.x, decelerationRate: decelerationRate), 93 | y: pipView.center.y + project(initialVelocity: velocity.y, decelerationRate: decelerationRate) 94 | ) 95 | let nearestCornerPosition = nearestCorner(to: projectedPosition) 96 | let relativeInitialVelocity = CGVector( 97 | dx: relativeVelocity(forVelocity: velocity.x, from: pipView.center.x, to: nearestCornerPosition.x), 98 | dy: relativeVelocity(forVelocity: velocity.y, from: pipView.center.y, to: nearestCornerPosition.y) 99 | ) 100 | let timingParameters = UISpringTimingParameters(damping: 1, response: 0.4, initialVelocity: relativeInitialVelocity) 101 | let animator = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters) 102 | animator.addAnimations { 103 | self.pipView.center = nearestCornerPosition 104 | } 105 | animator.startAnimation() 106 | default: break 107 | } 108 | } 109 | 110 | /// Distance traveled after decelerating to zero velocity at a constant rate. 111 | private func project(initialVelocity: CGFloat, decelerationRate: CGFloat) -> CGFloat { 112 | return (initialVelocity / 1000) * decelerationRate / (1 - decelerationRate) 113 | } 114 | 115 | /// Finds the position of the nearest corner to the given point. 116 | private func nearestCorner(to point: CGPoint) -> CGPoint { 117 | var minDistance = CGFloat.greatestFiniteMagnitude 118 | var closestPosition = CGPoint.zero 119 | for position in pipPositions { 120 | let distance = point.distance(to: position) 121 | if distance < minDistance { 122 | closestPosition = position 123 | minDistance = distance 124 | } 125 | } 126 | return closestPosition 127 | } 128 | 129 | /// Calculates the relative velocity needed for the initial velocity of the animation. 130 | private func relativeVelocity(forVelocity velocity: CGFloat, from currentValue: CGFloat, to targetValue: CGFloat) -> CGFloat { 131 | guard currentValue - targetValue != 0 else { return 0 } 132 | return velocity / (targetValue - currentValue) 133 | } 134 | 135 | } 136 | 137 | class PipPositionView: UIView { 138 | 139 | private lazy var shapeLayer: CAShapeLayer = { 140 | let layer = CAShapeLayer() 141 | layer.strokeColor = UIColor(white: 0.3, alpha: 1).cgColor 142 | layer.lineWidth = lineWidth 143 | return layer 144 | }() 145 | 146 | private let lineWidth: CGFloat = 2 147 | 148 | override init(frame: CGRect) { 149 | super.init(frame: frame) 150 | sharedInit() 151 | } 152 | 153 | required init?(coder aDecoder: NSCoder) { 154 | super.init(coder: aDecoder) 155 | sharedInit() 156 | } 157 | 158 | private func sharedInit() { 159 | layer.addSublayer(shapeLayer) 160 | } 161 | 162 | override func layoutSubviews() { 163 | super.layoutSubviews() 164 | shapeLayer.frame = bounds 165 | shapeLayer.path = UIBezierPath(roundedRect: bounds.insetBy(dx: lineWidth / 2, dy: lineWidth / 2), cornerRadius: 16).cgPath 166 | } 167 | 168 | } 169 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Rotation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Rotation.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/8/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class RotationInterfaceViewController: InterfaceViewController { 12 | 13 | private lazy var rotationView: GradientView = { 14 | let view = GradientView() 15 | view.topColor = UIColor(hex: 0xFF28A5) 16 | view.bottomColor = UIColor(hex: 0x7934CF) 17 | return view 18 | }() 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | 23 | view.addSubview(rotationView) 24 | rotationView.center(in: view) 25 | rotationView.widthAnchor.constraint(equalToConstant: 300).isActive = true 26 | rotationView.heightAnchor.constraint(equalToConstant: 300).isActive = true 27 | 28 | let rotationRecognizer = UIRotationGestureRecognizer() 29 | rotationRecognizer.addTarget(self, action: #selector(rotated(rotationRecognizer:))) 30 | rotationView.addGestureRecognizer(rotationRecognizer) 31 | 32 | } 33 | 34 | private var originalRotation: CGFloat = 0 35 | 36 | @objc private func rotated(rotationRecognizer: UIRotationGestureRecognizer) { 37 | switch rotationRecognizer.state { 38 | case .began: 39 | originalRotation = atan2(rotationView.transform.b, rotationView.transform.a) 40 | rotationView.transform = CGAffineTransform(rotationAngle: originalRotation + rotationRecognizer.rotation) 41 | case .changed: 42 | rotationView.transform = CGAffineTransform(rotationAngle: originalRotation + rotationRecognizer.rotation) 43 | case .ended, .cancelled: 44 | let decelerationRate = UIScrollView.DecelerationRate.fast.rawValue 45 | let velocity = rotationRecognizer.velocity 46 | let projectedRotation = rotationRecognizer.rotation + project(initialVelocity: velocity, decelerationRate: decelerationRate) 47 | let nearestAngle = closestAngle(to: projectedRotation) 48 | let relativeInitialVelocity = relativeVelocity(forVelocity: velocity, from: rotationRecognizer.rotation, to: nearestAngle) 49 | let timingParameters = UISpringTimingParameters(damping: 0.8, response: 0.4, initialVelocity: CGVector(dx: relativeInitialVelocity, dy: 0)) 50 | let animator = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters) 51 | animator.addAnimations { 52 | self.rotationView.transform = CGAffineTransform(rotationAngle: self.originalRotation + nearestAngle) 53 | } 54 | animator.startAnimation() 55 | default: break 56 | } 57 | } 58 | 59 | /// Distance traveled after decelerating to zero velocity at a constant rate. 60 | private func project(initialVelocity: CGFloat, decelerationRate: CGFloat) -> CGFloat { 61 | return (initialVelocity / 1000) * decelerationRate / (1 - decelerationRate) 62 | } 63 | 64 | private func closestAngle(to angle: CGFloat) -> CGFloat { 65 | let divisor: CGFloat = .pi / 2 66 | let remainder = angle.truncatingRemainder(dividingBy: divisor) 67 | var newAngle: CGFloat = 0 68 | if remainder >= 0 { 69 | if remainder >= divisor / 2 { 70 | newAngle = angle + divisor - remainder 71 | } else { 72 | newAngle = remainder == 0 ? angle : angle - remainder 73 | } 74 | } else { 75 | if remainder <= -divisor / 2 { 76 | newAngle = angle - divisor - remainder 77 | } else { 78 | newAngle = angle - remainder 79 | } 80 | } 81 | if newAngle > .pi { newAngle = .pi } 82 | if newAngle < -.pi { newAngle = -.pi } 83 | return newAngle 84 | } 85 | 86 | private func relativeVelocity(forVelocity velocity: CGFloat, from currentValue: CGFloat, to targetValue: CGFloat) -> CGFloat { 87 | guard currentValue - targetValue != 0 else { return 0 } 88 | return velocity / (targetValue - currentValue) 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Rubberbanding.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Rubberbanding.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/8/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class RubberbandingInterfaceViewController: InterfaceViewController { 12 | 13 | private lazy var rubberView: GradientView = { 14 | let view = GradientView() 15 | view.topColor = UIColor(hex: 0xFF5B50) 16 | view.bottomColor = UIColor(hex: 0xFFC950) 17 | return view 18 | }() 19 | 20 | private let panRecognier = UIPanGestureRecognizer() 21 | 22 | override func viewDidLoad() { 23 | super.viewDidLoad() 24 | 25 | view.addSubview(rubberView) 26 | rubberView.center(in: view) 27 | rubberView.widthAnchor.constraint(equalToConstant: 160).isActive = true 28 | rubberView.heightAnchor.constraint(equalToConstant: 160).isActive = true 29 | 30 | panRecognier.addTarget(self, action: #selector(panned(recognizer:))) 31 | rubberView.addGestureRecognizer(panRecognier) 32 | 33 | } 34 | 35 | private var originalTouchPoint: CGPoint = .zero 36 | 37 | @objc private func panned(recognizer: UIPanGestureRecognizer) { 38 | let touchPoint = recognizer.location(in: view) 39 | switch recognizer.state { 40 | case .began: 41 | originalTouchPoint = touchPoint 42 | case .changed: 43 | var offset = touchPoint.y - originalTouchPoint.y 44 | offset = offset > 0 ? pow(offset, 0.7) : -pow(-offset, 0.7) 45 | rubberView.transform = CGAffineTransform(translationX: 0, y: offset) 46 | case .ended, .cancelled: 47 | let timingParameters = UISpringTimingParameters(damping: 0.6, response: 0.3) 48 | let animator = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters) 49 | animator.addAnimations { 50 | self.rubberView.transform = .identity 51 | } 52 | animator.isInterruptible = true 53 | animator.startAnimation() 54 | default: break 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/Spring.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Spring.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/8/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SpringInterfaceViewController: InterfaceViewController { 12 | 13 | private lazy var springView: GradientView = { 14 | let view = GradientView() 15 | view.translatesAutoresizingMaskIntoConstraints = false 16 | view.topColor = UIColor(hex: 0x64CCF7) 17 | view.bottomColor = UIColor(hex: 0x359EEC) 18 | return view 19 | }() 20 | 21 | private lazy var dampingSliderView: SliderView = { 22 | let sliderView = SliderView() 23 | sliderView.translatesAutoresizingMaskIntoConstraints = false 24 | sliderView.title = "DAMPING (BOUNCINESS)" 25 | sliderView.minValue = 0.1 26 | sliderView.maxValue = 1 27 | sliderView.value = dampingRatio 28 | sliderView.sliderMovedAction = { self.dampingRatio = $0 } 29 | sliderView.sliderFinishedMovingAction = { self.resetAnimation() } 30 | return sliderView 31 | }() 32 | 33 | private lazy var frequencySliderView: SliderView = { 34 | let sliderView = SliderView() 35 | sliderView.translatesAutoresizingMaskIntoConstraints = false 36 | sliderView.title = "RESPONSE (SPEED)" 37 | sliderView.minValue = 0.1 38 | sliderView.maxValue = 2 39 | sliderView.value = frequencyResponse 40 | sliderView.sliderMovedAction = { self.frequencyResponse = $0 } 41 | sliderView.sliderFinishedMovingAction = { self.resetAnimation() } 42 | return sliderView 43 | }() 44 | 45 | private var dampingRatio: CGFloat = 0.5 46 | private var frequencyResponse: CGFloat = 1 47 | 48 | private let margin: CGFloat = 30 49 | 50 | override func viewDidLoad() { 51 | super.viewDidLoad() 52 | 53 | view.addSubview(dampingSliderView) 54 | dampingSliderView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: margin).isActive = true 55 | dampingSliderView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -margin).isActive = true 56 | dampingSliderView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 0).isActive = true 57 | 58 | view.addSubview(frequencySliderView) 59 | frequencySliderView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: margin).isActive = true 60 | frequencySliderView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -margin).isActive = true 61 | frequencySliderView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 140).isActive = true 62 | 63 | view.addSubview(springView) 64 | springView.heightAnchor.constraint(equalToConstant: 80).isActive = true 65 | springView.widthAnchor.constraint(equalToConstant: 80).isActive = true 66 | springView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: margin).isActive = true 67 | springView.bottomAnchor.constraint(equalTo: dampingSliderView.topAnchor, constant: -80).isActive = true 68 | 69 | animateView() 70 | 71 | } 72 | 73 | private var animator = UIViewPropertyAnimator() 74 | 75 | /// Repeatedly animates the view using the current `dampingRatio` and `frequencyResponse`. 76 | private func animateView() { 77 | let timingParameters = UISpringTimingParameters(damping: dampingRatio, response: frequencyResponse) 78 | animator = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters) 79 | animator.addAnimations { 80 | let translation = self.view.bounds.width - 2 * self.margin - 80 81 | self.springView.transform = CGAffineTransform(translationX: translation, y: 0) 82 | } 83 | animator.addCompletion { _ in 84 | self.springView.transform = .identity 85 | self.animateView() 86 | } 87 | animator.startAnimation() 88 | } 89 | 90 | private func resetAnimation() { 91 | animator.stopAnimation(true) 92 | self.springView.transform = .identity 93 | animateView() 94 | } 95 | 96 | } 97 | 98 | /// A view that displays a title, value, and slider. 99 | class SliderView: UIView { 100 | 101 | public var title: String = "" { 102 | didSet { 103 | titleLabel.text = title 104 | } 105 | } 106 | 107 | public var value: CGFloat { 108 | get { 109 | return CGFloat(slider.value) 110 | } 111 | set { 112 | slider.value = Float(newValue) 113 | valueLabel.text = String(format: "%.2f", newValue) 114 | } 115 | } 116 | 117 | public var minValue: CGFloat = 0 { 118 | didSet { 119 | slider.minimumValue = Float(minValue) 120 | } 121 | } 122 | 123 | public var maxValue: CGFloat = 1 { 124 | didSet { 125 | slider.maximumValue = Float(maxValue) 126 | } 127 | } 128 | 129 | /// Code that's executed when the slider moves. 130 | public var sliderMovedAction: (CGFloat) -> () = { _ in } 131 | 132 | /// Code that's executed when the slider has finished moving. 133 | public var sliderFinishedMovingAction: () -> () = {} 134 | 135 | private lazy var titleLabel: UILabel = { 136 | let label = UILabel() 137 | label.translatesAutoresizingMaskIntoConstraints = false 138 | label.font = UIFont.systemFont(ofSize: 16, weight: .bold) 139 | label.textColor = .white 140 | return label 141 | }() 142 | 143 | private lazy var slider: UISlider = { 144 | let slider = UISlider() 145 | slider.translatesAutoresizingMaskIntoConstraints = false 146 | slider.addTarget(self, action: #selector(sliderMoved(slider:event:)), for: .valueChanged) 147 | return slider 148 | }() 149 | 150 | private lazy var valueLabel: UILabel = { 151 | let label = UILabel() 152 | label.translatesAutoresizingMaskIntoConstraints = false 153 | label.font = UIFont.systemFont(ofSize: 16, weight: .bold) 154 | label.textColor = .white 155 | label.text = "0" 156 | return label 157 | }() 158 | 159 | override init(frame: CGRect) { 160 | super.init(frame: frame) 161 | sharedInit() 162 | } 163 | 164 | required init?(coder aDecoder: NSCoder) { 165 | super.init(coder: aDecoder) 166 | sharedInit() 167 | } 168 | 169 | private func sharedInit() { 170 | 171 | addSubview(titleLabel) 172 | titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true 173 | titleLabel.topAnchor.constraint(equalTo: topAnchor).isActive = true 174 | 175 | addSubview(valueLabel) 176 | valueLabel.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true 177 | valueLabel.lastBaselineAnchor.constraint(equalTo: titleLabel.lastBaselineAnchor).isActive = true 178 | 179 | addSubview(slider) 180 | slider.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true 181 | slider.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true 182 | slider.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true 183 | slider.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 20).isActive = true 184 | 185 | } 186 | 187 | @objc private func sliderMoved(slider: UISlider, event: UIEvent) { 188 | valueLabel.text = String(format: "%.2f", slider.value) 189 | sliderMovedAction(CGFloat(slider.value)) 190 | if event.allTouches?.first?.phase == .ended { sliderFinishedMovingAction() } 191 | } 192 | 193 | } 194 | 195 | extension UISpringTimingParameters { 196 | 197 | /// A design-friendly way to create a spring timing curve. 198 | /// 199 | /// - Parameters: 200 | /// - damping: The 'bounciness' of the animation. Value must be between 0 and 1. 201 | /// - response: The 'speed' of the animation. 202 | /// - initialVelocity: The vector describing the starting motion of the property. Optional, default is `.zero`. 203 | public convenience init(damping: CGFloat, response: CGFloat, initialVelocity: CGVector = .zero) { 204 | let stiffness = pow(2 * .pi / response, 2) 205 | let damp = 4 * .pi * damping / response 206 | self.init(mass: 1, stiffness: stiffness, damping: damp, initialVelocity: initialVelocity) 207 | } 208 | 209 | } 210 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/SwiftExtensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftExtensions.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Maksym Shcheglov on 19/08/2018. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | #if swift(>=4.2) 12 | #else 13 | public extension UIScrollView { 14 | enum DecelerationRate: CGFloat { 15 | case normal = 0.998 16 | case fast = 0.99 17 | } 18 | } 19 | 20 | public extension Bool { 21 | mutating func toggle() { 22 | self = !self 23 | } 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/UIColorExtensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIColorExtensions.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/12/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIColor { 12 | convenience init(hex: Int, alpha: CGFloat = 1) { 13 | let r = CGFloat((hex & 0xFF0000) >> 16) / 255 14 | let g = CGFloat((hex & 0xFF00) >> 8) / 255 15 | let b = CGFloat((hex & 0xFF)) / 255 16 | self.init(red: r, green: g, blue: b, alpha: alpha) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /FluidInterfaces/FluidInterfaces/UIViewExtensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIViewExtensions.swift 3 | // FluidInterfaces 4 | // 5 | // Created by Nathan Gitter on 7/12/18. 6 | // Copyright © 2018 Nathan Gitter. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIView { 12 | 13 | static func activate(constraints: [NSLayoutConstraint]) { 14 | constraints.forEach { ($0.firstItem as? UIView)?.translatesAutoresizingMaskIntoConstraints = false } 15 | NSLayoutConstraint.activate(constraints) 16 | } 17 | 18 | func pin(to view: UIView, insets: UIEdgeInsets = .zero) { 19 | UIView.activate(constraints: [ 20 | topAnchor.constraint(equalTo: view.topAnchor, constant: insets.top), 21 | leftAnchor.constraint(equalTo: view.leftAnchor, constant: insets.left), 22 | bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -insets.bottom), 23 | rightAnchor.constraint(equalTo: view.rightAnchor, constant: -insets.right) 24 | ]) 25 | } 26 | 27 | func center(in view: UIView, offset: UIOffset = .zero) { 28 | UIView.activate(constraints: [ 29 | centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: offset.horizontal), 30 | centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: offset.vertical) 31 | ]) 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Fluid Interfaces Title Graphic

2 | 3 | ### Check out the accompanying blog post for more details: [Building Fluid Interfaces](https://medium.com/@nathangitter/building-fluid-interfaces-ios-swift-9732bb934bf5) 4 | 5 | ⭐️ If you found this repo helpful, please star it. Thanks! ⭐️ 6 | 7 | ### Background 8 | 9 | At WWDC 2018, Apple designers gave a talk titled "Designing Fluid Interfaces", explaining the design theory behind the gesture-based interface of iPhone X. (The presentation is available here: [Designing Fluid Interfaces](https://developer.apple.com/videos/play/wwdc2018/803/)) 10 | 11 | It was an outstanding talk, inspiring designers and developers to think about animated interfaces in a new way. While some technical guidance was provided, most code-level implementation details were ommitted. 12 | 13 | The goal with this project is to bridge the gap between inspiration and implementation. 14 | 15 | ### Installation 16 | 17 | Download or clone the repo and open the `FluidInterfaces.xcodeproj` file with Xcode. 18 | 19 | ### Interfaces 20 | 21 | [Calculator Button](#calculator-button) 22 | 23 | [Spring Animations](#spring-animations) 24 | 25 | [Flashlight Button](#flashlight-button) 26 | 27 | [Rubberbanding](#rubberbanding) 28 | 29 | [Acceleration Pausing](#acceleration-pausing) 30 | 31 | [Rewarding Momentum](#rewarding-momentum) 32 | 33 | [FaceTime PiP](#facetime-pip) 34 | 35 | [Rotation](#rotation) 36 | 37 | ## Calculator Button 38 | 39 | A button that mimics the behavior of buttons in the iOS Calculator app. 40 | 41 | Calculator Button Demo 42 | 43 | [⚙️ CalculatorButton.swift](FluidInterfaces/FluidInterfaces/CalculatorButton.swift) 44 | 45 | [📺 Designing Fluid Interfaces 50:13](https://developer.apple.com/videos/play/wwdc2018/803/?time=3013) 46 | 47 | ## Spring Animations 48 | 49 | A demo showing the ability to define a spring animation with "design-friendly" parameters. 50 | 51 | Spring Demo 52 | 53 | [⚙️ Spring.swift](FluidInterfaces/FluidInterfaces/Spring.swift) 54 | 55 | [📺 Designing Fluid Interfaces 31:40](https://developer.apple.com/videos/play/wwdc2018/803/?time=1900) 56 | 57 | ## Flashlight Button 58 | 59 | A button that mimics the behavior of the flashlight button on the lockscreen of iPhone X. 60 | 61 | Flashlight Button Demo 62 | 63 | [⚙️ FlashlightButton.swift](FluidInterfaces/FluidInterfaces/FlashlightButton.swift) 64 | 65 | [📺 Designing Fluid Interfaces 37:59](https://developer.apple.com/videos/play/wwdc2018/803/?time=2279) 66 | 67 | ## Rubberbanding 68 | 69 | A demo showing how to implement rubberbanding. 70 | 71 | Rubberbanding Demo 72 | 73 | [⚙️ Rubberbanding.swift](FluidInterfaces/FluidInterfaces/Rubberbanding.swift) 74 | 75 | [📺 Designing Fluid Interfaces 17:01](https://developer.apple.com/videos/play/wwdc2018/803/?time=1021) 76 | 77 | ## Acceleration Pausing 78 | 79 | A demo of using a gesture's acceleration to quickly detect when the user's motion has paused. 80 | 81 | Acceleration Pausing Demo 82 | 83 | [⚙️ Acceleration.swift](FluidInterfaces/FluidInterfaces/Acceleration.swift) 84 | 85 | [📺 Designing Fluid Interfaces 10:40](https://developer.apple.com/videos/play/wwdc2018/803/?time=640) 86 | 87 | ## Rewarding Momentum 88 | 89 | A drawer with an open and closed state which has bounciness dependent on the velocity of the gesture. 90 | 91 | Rewarding Momentum Demo 92 | 93 | [⚙️ Momentum.swift](FluidInterfaces/FluidInterfaces/Momentum.swift) 94 | 95 | [📺 Designing Fluid Interfaces 36:48](https://developer.apple.com/videos/play/wwdc2018/803/?time=2208) 96 | 97 | ## FaceTime PiP 98 | 99 | A re-creation of the picture-in-picture UI of the iOS FaceTime app. 100 | 101 | FaceTime PiP Demo 102 | 103 | [⚙️ Pip.swift](FluidInterfaces/FluidInterfaces/Pip.swift) 104 | 105 | [📺 Designing Fluid Interfaces 41:56](https://developer.apple.com/videos/play/wwdc2018/803/?time=2516) 106 | 107 | ## Rotation 108 | 109 | A demo showing how the concepts from the PiP interface can apply to other animations. 110 | 111 | Rotation Demo 112 | 113 | [⚙️ Rotation.swift](FluidInterfaces/FluidInterfaces/Rotation.swift) 114 | 115 | [📺 Designing Fluid Interfaces 47:25](https://developer.apple.com/videos/play/wwdc2018/803/?time=2845) 116 | 117 | ## Author 118 | You can find me on Twitter [@nathangitter](https://twitter.com/nathangitter) 119 | 120 | ## Contributing 121 | Feel free to add issues or pull requests here on GitHub. I cannot guarantee that I will accept your changes, but feel free to fork the repo and make changes as you see fit. Thanks! 122 | 123 | ## License & Copyright 124 | © 2018 Nathan Gitter, licensed under Apache-2.0. See LICENSE for more information. 125 | -------------------------------------------------------------------------------- /Resources/accelerationdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/Resources/accelerationdemo.gif -------------------------------------------------------------------------------- /Resources/calcdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/Resources/calcdemo.gif -------------------------------------------------------------------------------- /Resources/flashdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/Resources/flashdemo.gif -------------------------------------------------------------------------------- /Resources/momentumdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/Resources/momentumdemo.gif -------------------------------------------------------------------------------- /Resources/pipdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/Resources/pipdemo.gif -------------------------------------------------------------------------------- /Resources/repo-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/Resources/repo-banner.png -------------------------------------------------------------------------------- /Resources/rotationdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/Resources/rotationdemo.gif -------------------------------------------------------------------------------- /Resources/rubberdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/Resources/rubberdemo.gif -------------------------------------------------------------------------------- /Resources/springdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathangitter/fluid-interfaces/da5c66cc5f7986339ed29c6b6d995bbd1f8b0a8b/Resources/springdemo.gif --------------------------------------------------------------------------------