├── README.md ├── Shapedemo.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata └── Shapedemo ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj ├── LaunchScreen.xib └── Main.storyboard ├── Images.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m /README.md: -------------------------------------------------------------------------------- 1 | # Interactive shapes - iOS demo 2 | A quick demo made for [this Dribble shot](https://dribbble.com/shots/1950331-Interactive-shapes-iOS-demo). 3 | 4 | It basically just draws two simple bezier curves, something like this: 5 | 6 | ![curves](http://i.imgur.com/kZX2VXQ.png) 7 | 8 | The "tip" is placed based on pan with fixed control points, and control points of the top and bottom left corners are stretched a bit according to pan's translation along Y axis to make a nicer curve. 9 | -------------------------------------------------------------------------------- /Shapedemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | DCEFD6CF1A9FBBF40011A1FC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = DCEFD6CE1A9FBBF40011A1FC /* main.m */; }; 11 | DCEFD6D21A9FBBF40011A1FC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = DCEFD6D11A9FBBF40011A1FC /* AppDelegate.m */; }; 12 | DCEFD6D51A9FBBF40011A1FC /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DCEFD6D41A9FBBF40011A1FC /* ViewController.m */; }; 13 | DCEFD6D81A9FBBF40011A1FC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DCEFD6D61A9FBBF40011A1FC /* Main.storyboard */; }; 14 | DCEFD6DA1A9FBBF40011A1FC /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DCEFD6D91A9FBBF40011A1FC /* Images.xcassets */; }; 15 | DCEFD6DD1A9FBBF40011A1FC /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = DCEFD6DB1A9FBBF40011A1FC /* LaunchScreen.xib */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | DCEFD6C91A9FBBF40011A1FC /* Shapedemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Shapedemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | DCEFD6CD1A9FBBF40011A1FC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 21 | DCEFD6CE1A9FBBF40011A1FC /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 22 | DCEFD6D01A9FBBF40011A1FC /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 23 | DCEFD6D11A9FBBF40011A1FC /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 24 | DCEFD6D31A9FBBF40011A1FC /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 25 | DCEFD6D41A9FBBF40011A1FC /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 26 | DCEFD6D71A9FBBF40011A1FC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | DCEFD6D91A9FBBF40011A1FC /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 28 | DCEFD6DC1A9FBBF40011A1FC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | DCEFD6C61A9FBBF40011A1FC /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | DCEFD6C01A9FBBF40011A1FC = { 43 | isa = PBXGroup; 44 | children = ( 45 | DCEFD6CB1A9FBBF40011A1FC /* Shapedemo */, 46 | DCEFD6CA1A9FBBF40011A1FC /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | DCEFD6CA1A9FBBF40011A1FC /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | DCEFD6C91A9FBBF40011A1FC /* Shapedemo.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | DCEFD6CB1A9FBBF40011A1FC /* Shapedemo */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | DCEFD6D01A9FBBF40011A1FC /* AppDelegate.h */, 62 | DCEFD6D11A9FBBF40011A1FC /* AppDelegate.m */, 63 | DCEFD6D31A9FBBF40011A1FC /* ViewController.h */, 64 | DCEFD6D41A9FBBF40011A1FC /* ViewController.m */, 65 | DCEFD6D61A9FBBF40011A1FC /* Main.storyboard */, 66 | DCEFD6D91A9FBBF40011A1FC /* Images.xcassets */, 67 | DCEFD6DB1A9FBBF40011A1FC /* LaunchScreen.xib */, 68 | DCEFD6CC1A9FBBF40011A1FC /* Supporting Files */, 69 | ); 70 | path = Shapedemo; 71 | sourceTree = ""; 72 | }; 73 | DCEFD6CC1A9FBBF40011A1FC /* Supporting Files */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | DCEFD6CD1A9FBBF40011A1FC /* Info.plist */, 77 | DCEFD6CE1A9FBBF40011A1FC /* main.m */, 78 | ); 79 | name = "Supporting Files"; 80 | sourceTree = ""; 81 | }; 82 | /* End PBXGroup section */ 83 | 84 | /* Begin PBXNativeTarget section */ 85 | DCEFD6C81A9FBBF40011A1FC /* Shapedemo */ = { 86 | isa = PBXNativeTarget; 87 | buildConfigurationList = DCEFD6EC1A9FBBF40011A1FC /* Build configuration list for PBXNativeTarget "Shapedemo" */; 88 | buildPhases = ( 89 | DCEFD6C51A9FBBF40011A1FC /* Sources */, 90 | DCEFD6C61A9FBBF40011A1FC /* Frameworks */, 91 | DCEFD6C71A9FBBF40011A1FC /* Resources */, 92 | ); 93 | buildRules = ( 94 | ); 95 | dependencies = ( 96 | ); 97 | name = Shapedemo; 98 | productName = Shapedemo; 99 | productReference = DCEFD6C91A9FBBF40011A1FC /* Shapedemo.app */; 100 | productType = "com.apple.product-type.application"; 101 | }; 102 | /* End PBXNativeTarget section */ 103 | 104 | /* Begin PBXProject section */ 105 | DCEFD6C11A9FBBF40011A1FC /* Project object */ = { 106 | isa = PBXProject; 107 | attributes = { 108 | LastUpgradeCheck = 0610; 109 | ORGANIZATIONNAME = "Filip Radelic"; 110 | TargetAttributes = { 111 | DCEFD6C81A9FBBF40011A1FC = { 112 | CreatedOnToolsVersion = 6.1.1; 113 | }; 114 | }; 115 | }; 116 | buildConfigurationList = DCEFD6C41A9FBBF40011A1FC /* Build configuration list for PBXProject "Shapedemo" */; 117 | compatibilityVersion = "Xcode 3.2"; 118 | developmentRegion = English; 119 | hasScannedForEncodings = 0; 120 | knownRegions = ( 121 | en, 122 | Base, 123 | ); 124 | mainGroup = DCEFD6C01A9FBBF40011A1FC; 125 | productRefGroup = DCEFD6CA1A9FBBF40011A1FC /* Products */; 126 | projectDirPath = ""; 127 | projectRoot = ""; 128 | targets = ( 129 | DCEFD6C81A9FBBF40011A1FC /* Shapedemo */, 130 | ); 131 | }; 132 | /* End PBXProject section */ 133 | 134 | /* Begin PBXResourcesBuildPhase section */ 135 | DCEFD6C71A9FBBF40011A1FC /* Resources */ = { 136 | isa = PBXResourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | DCEFD6D81A9FBBF40011A1FC /* Main.storyboard in Resources */, 140 | DCEFD6DD1A9FBBF40011A1FC /* LaunchScreen.xib in Resources */, 141 | DCEFD6DA1A9FBBF40011A1FC /* Images.xcassets in Resources */, 142 | ); 143 | runOnlyForDeploymentPostprocessing = 0; 144 | }; 145 | /* End PBXResourcesBuildPhase section */ 146 | 147 | /* Begin PBXSourcesBuildPhase section */ 148 | DCEFD6C51A9FBBF40011A1FC /* Sources */ = { 149 | isa = PBXSourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | DCEFD6D51A9FBBF40011A1FC /* ViewController.m in Sources */, 153 | DCEFD6D21A9FBBF40011A1FC /* AppDelegate.m in Sources */, 154 | DCEFD6CF1A9FBBF40011A1FC /* main.m in Sources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXSourcesBuildPhase section */ 159 | 160 | /* Begin PBXVariantGroup section */ 161 | DCEFD6D61A9FBBF40011A1FC /* Main.storyboard */ = { 162 | isa = PBXVariantGroup; 163 | children = ( 164 | DCEFD6D71A9FBBF40011A1FC /* Base */, 165 | ); 166 | name = Main.storyboard; 167 | sourceTree = ""; 168 | }; 169 | DCEFD6DB1A9FBBF40011A1FC /* LaunchScreen.xib */ = { 170 | isa = PBXVariantGroup; 171 | children = ( 172 | DCEFD6DC1A9FBBF40011A1FC /* Base */, 173 | ); 174 | name = LaunchScreen.xib; 175 | sourceTree = ""; 176 | }; 177 | /* End PBXVariantGroup section */ 178 | 179 | /* Begin XCBuildConfiguration section */ 180 | DCEFD6EA1A9FBBF40011A1FC /* Debug */ = { 181 | isa = XCBuildConfiguration; 182 | buildSettings = { 183 | ALWAYS_SEARCH_USER_PATHS = NO; 184 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 185 | CLANG_CXX_LIBRARY = "libc++"; 186 | CLANG_ENABLE_MODULES = YES; 187 | CLANG_ENABLE_OBJC_ARC = YES; 188 | CLANG_WARN_BOOL_CONVERSION = YES; 189 | CLANG_WARN_CONSTANT_CONVERSION = YES; 190 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 191 | CLANG_WARN_EMPTY_BODY = YES; 192 | CLANG_WARN_ENUM_CONVERSION = YES; 193 | CLANG_WARN_INT_CONVERSION = YES; 194 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 195 | CLANG_WARN_UNREACHABLE_CODE = YES; 196 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 197 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 198 | COPY_PHASE_STRIP = NO; 199 | ENABLE_STRICT_OBJC_MSGSEND = YES; 200 | GCC_C_LANGUAGE_STANDARD = gnu99; 201 | GCC_DYNAMIC_NO_PIC = NO; 202 | GCC_OPTIMIZATION_LEVEL = 0; 203 | GCC_PREPROCESSOR_DEFINITIONS = ( 204 | "DEBUG=1", 205 | "$(inherited)", 206 | ); 207 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 208 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 209 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 210 | GCC_WARN_UNDECLARED_SELECTOR = YES; 211 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 212 | GCC_WARN_UNUSED_FUNCTION = YES; 213 | GCC_WARN_UNUSED_VARIABLE = YES; 214 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 215 | MTL_ENABLE_DEBUG_INFO = YES; 216 | ONLY_ACTIVE_ARCH = YES; 217 | SDKROOT = iphoneos; 218 | TARGETED_DEVICE_FAMILY = "1,2"; 219 | }; 220 | name = Debug; 221 | }; 222 | DCEFD6EB1A9FBBF40011A1FC /* Release */ = { 223 | isa = XCBuildConfiguration; 224 | buildSettings = { 225 | ALWAYS_SEARCH_USER_PATHS = NO; 226 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 227 | CLANG_CXX_LIBRARY = "libc++"; 228 | CLANG_ENABLE_MODULES = YES; 229 | CLANG_ENABLE_OBJC_ARC = YES; 230 | CLANG_WARN_BOOL_CONVERSION = YES; 231 | CLANG_WARN_CONSTANT_CONVERSION = YES; 232 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 233 | CLANG_WARN_EMPTY_BODY = YES; 234 | CLANG_WARN_ENUM_CONVERSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 237 | CLANG_WARN_UNREACHABLE_CODE = YES; 238 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 239 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 240 | COPY_PHASE_STRIP = YES; 241 | ENABLE_NS_ASSERTIONS = NO; 242 | ENABLE_STRICT_OBJC_MSGSEND = YES; 243 | GCC_C_LANGUAGE_STANDARD = gnu99; 244 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 245 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 246 | GCC_WARN_UNDECLARED_SELECTOR = YES; 247 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 248 | GCC_WARN_UNUSED_FUNCTION = YES; 249 | GCC_WARN_UNUSED_VARIABLE = YES; 250 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 251 | MTL_ENABLE_DEBUG_INFO = NO; 252 | SDKROOT = iphoneos; 253 | TARGETED_DEVICE_FAMILY = "1,2"; 254 | VALIDATE_PRODUCT = YES; 255 | }; 256 | name = Release; 257 | }; 258 | DCEFD6ED1A9FBBF40011A1FC /* Debug */ = { 259 | isa = XCBuildConfiguration; 260 | buildSettings = { 261 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 262 | INFOPLIST_FILE = Shapedemo/Info.plist; 263 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 264 | PRODUCT_NAME = "$(TARGET_NAME)"; 265 | }; 266 | name = Debug; 267 | }; 268 | DCEFD6EE1A9FBBF40011A1FC /* Release */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 272 | INFOPLIST_FILE = Shapedemo/Info.plist; 273 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 274 | PRODUCT_NAME = "$(TARGET_NAME)"; 275 | }; 276 | name = Release; 277 | }; 278 | /* End XCBuildConfiguration section */ 279 | 280 | /* Begin XCConfigurationList section */ 281 | DCEFD6C41A9FBBF40011A1FC /* Build configuration list for PBXProject "Shapedemo" */ = { 282 | isa = XCConfigurationList; 283 | buildConfigurations = ( 284 | DCEFD6EA1A9FBBF40011A1FC /* Debug */, 285 | DCEFD6EB1A9FBBF40011A1FC /* Release */, 286 | ); 287 | defaultConfigurationIsVisible = 0; 288 | defaultConfigurationName = Release; 289 | }; 290 | DCEFD6EC1A9FBBF40011A1FC /* Build configuration list for PBXNativeTarget "Shapedemo" */ = { 291 | isa = XCConfigurationList; 292 | buildConfigurations = ( 293 | DCEFD6ED1A9FBBF40011A1FC /* Debug */, 294 | DCEFD6EE1A9FBBF40011A1FC /* Release */, 295 | ); 296 | defaultConfigurationIsVisible = 0; 297 | }; 298 | /* End XCConfigurationList section */ 299 | }; 300 | rootObject = DCEFD6C11A9FBBF40011A1FC /* Project object */; 301 | } 302 | -------------------------------------------------------------------------------- /Shapedemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Shapedemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | @import UIKit; 2 | 3 | @interface AppDelegate : UIResponder 4 | 5 | @property (strong, nonatomic) UIWindow *window; 6 | 7 | @end -------------------------------------------------------------------------------- /Shapedemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | @implementation AppDelegate 4 | 5 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 6 | { 7 | return YES; 8 | } 9 | 10 | @end -------------------------------------------------------------------------------- /Shapedemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Shapedemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Shapedemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Shapedemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.fichek.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 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 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Shapedemo/ViewController.h: -------------------------------------------------------------------------------- 1 | @import UIKit; 2 | 3 | @interface ViewController : UIViewController 4 | 5 | @end -------------------------------------------------------------------------------- /Shapedemo/ViewController.m: -------------------------------------------------------------------------------- 1 | #import "ViewController.h" 2 | 3 | @interface ViewController () 4 | 5 | @property (nonatomic, strong) CAShapeLayer *shapeLayer; 6 | @property (nonatomic, strong) UIBezierPath *path; 7 | 8 | @end 9 | 10 | @implementation ViewController 11 | 12 | - (void)viewDidLoad 13 | { 14 | [super viewDidLoad]; 15 | 16 | UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panned:)]; 17 | [self.view addGestureRecognizer:pan]; 18 | 19 | self.path = [[UIBezierPath alloc] init]; 20 | 21 | self.shapeLayer = [[CAShapeLayer alloc] init]; 22 | self.shapeLayer.fillColor = [UIColor darkGrayColor].CGColor; 23 | [self.view.layer insertSublayer:self.shapeLayer atIndex:0]; 24 | } 25 | 26 | - (void)panned:(UIPanGestureRecognizer *)pan 27 | { 28 | CGFloat h = CGRectGetHeight(self.view.frame); 29 | CGFloat innerControlPointRatio = 0.7; 30 | CGFloat outerControlPointDistance = 75; 31 | 32 | // we want the y position of touch, but we only want the translation along x axis for smooth start 33 | CGPoint touchPoint = CGPointMake([pan translationInView:pan.view].x, [pan locationInView:pan.view].y); 34 | 35 | if (pan.state == UIGestureRecognizerStateBegan || pan.state == UIGestureRecognizerStateChanged) { 36 | [self.path removeAllPoints]; 37 | [self.path moveToPoint:CGPointZero]; 38 | 39 | // Next two methods are the key part. 40 | // Bezier curve from top left edge to touch point, 41 | [self.path addCurveToPoint:CGPointMake(touchPoint.x, touchPoint.y) 42 | controlPoint1:CGPointMake(0, touchPoint.y * innerControlPointRatio) 43 | controlPoint2:CGPointMake(touchPoint.x, touchPoint.y - outerControlPointDistance)]; 44 | // and from touch point to bottom left edge. 45 | [self.path addCurveToPoint:CGPointMake(0, h) 46 | controlPoint1:CGPointMake(touchPoint.x, touchPoint.y + outerControlPointDistance) 47 | controlPoint2:CGPointMake(0, touchPoint.y + (h - touchPoint.y) * (1.0 - innerControlPointRatio))]; 48 | [self.path closePath]; 49 | } 50 | else if (pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateCancelled) { 51 | // When pan is done animate the shape layer back to line. 52 | // However, for path morphing animation to work, it needs 53 | // to have same number of points as current path (3). 54 | // Also, this could be done with just 2 lines, but we'll 55 | // use curves insted for morphing to be smoother. 56 | // With lines there would be a pointy tip visible towards end. 57 | [self.path removeAllPoints]; 58 | [self.path moveToPoint:CGPointZero]; 59 | [self.path addCurveToPoint:CGPointMake(0, touchPoint.y) 60 | controlPoint1:CGPointMake(0, touchPoint.y * innerControlPointRatio) 61 | controlPoint2:CGPointMake(0, touchPoint.y - outerControlPointDistance)]; 62 | [self.path addCurveToPoint:CGPointMake(0, h) 63 | controlPoint1:CGPointMake(0, touchPoint.y + outerControlPointDistance) 64 | controlPoint2:CGPointMake(0, touchPoint.y + (h - touchPoint.y) * (1.0 - innerControlPointRatio))]; 65 | [self.path closePath]; 66 | 67 | CABasicAnimation *returnAnimation = [CABasicAnimation animationWithKeyPath:@"path"]; 68 | returnAnimation.toValue = self.path; 69 | [self.shapeLayer addAnimation:returnAnimation forKey:nil]; 70 | } 71 | 72 | // Give the new path to shape layer to draw. 73 | // Disable actions to prevent implicit animation 74 | // since we are drawing every frame manually during 75 | // pan, or adding explicit animation when pan ends. 76 | [CATransaction begin]; 77 | [CATransaction setDisableActions:YES]; 78 | self.shapeLayer.path = self.path.CGPath; 79 | [CATransaction commit]; 80 | } 81 | 82 | @end -------------------------------------------------------------------------------- /Shapedemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Shapedemo 4 | // 5 | // Created by Filip Radelic on 26/02/15. 6 | // Copyright (c) 2015 Filip Radelic. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------