├── DragAndDropInCollectionView.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── payalgupta.xcuserdatad │ └── xcschemes │ ├── DragAndDropInCollectionView.xcscheme │ └── xcschememanagement.plist ├── DragAndDropInCollectionView ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── chrome.imageset │ │ ├── Contents.json │ │ └── chrome.png │ ├── fade.imageset │ │ ├── Contents.json │ │ └── fade.png │ ├── falseColor.imageset │ │ ├── Contents.json │ │ └── falseColor.png │ ├── instant.imageset │ │ ├── Contents.json │ │ └── instant.png │ ├── mono.imageset │ │ ├── Contents.json │ │ └── mono.png │ ├── noir.imageset │ │ ├── Contents.json │ │ └── noir.png │ ├── none.imageset │ │ ├── Contents.json │ │ └── none.png │ ├── pin.imageset │ │ ├── Contents.json │ │ └── thumbtack-pushpin-2-hi.png │ ├── process.imageset │ │ ├── Contents.json │ │ └── process.png │ ├── sepia.imageset │ │ ├── Contents.json │ │ └── sepia.png │ ├── texture.imageset │ │ ├── Contents.json │ │ └── grunge-texture-abstract-hd-wallpaper-2560x1440-8066.png │ ├── tonal.imageset │ │ ├── Contents.json │ │ └── tonal.png │ └── transfer.imageset │ │ ├── Contents.json │ │ └── transfer.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── DragDropCollectionViewCell.swift ├── DragDropViewController.swift └── Info.plist ├── DragDrop.gif ├── LICENSE └── README.md /DragAndDropInCollectionView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | BD8FA17F1FB0912200B6C3C8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8FA17E1FB0912200B6C3C8 /* AppDelegate.swift */; }; 11 | BD8FA1811FB0912200B6C3C8 /* DragDropViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8FA1801FB0912200B6C3C8 /* DragDropViewController.swift */; }; 12 | BD8FA1841FB0912200B6C3C8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BD8FA1821FB0912200B6C3C8 /* Main.storyboard */; }; 13 | BD8FA1861FB0912200B6C3C8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BD8FA1851FB0912200B6C3C8 /* Assets.xcassets */; }; 14 | BD8FA1891FB0912200B6C3C8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BD8FA1871FB0912200B6C3C8 /* LaunchScreen.storyboard */; }; 15 | BDA631AC1FB31A3700A9DCF6 /* DragDropCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDA631AB1FB31A3700A9DCF6 /* DragDropCollectionViewCell.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | BD8FA17B1FB0912200B6C3C8 /* DragAndDropInCollectionView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DragAndDropInCollectionView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | BD8FA17E1FB0912200B6C3C8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | BD8FA1801FB0912200B6C3C8 /* DragDropViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DragDropViewController.swift; sourceTree = ""; }; 22 | BD8FA1831FB0912200B6C3C8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | BD8FA1851FB0912200B6C3C8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | BD8FA1881FB0912200B6C3C8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | BD8FA18A1FB0912200B6C3C8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | BDA631AB1FB31A3700A9DCF6 /* DragDropCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DragDropCollectionViewCell.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | BD8FA1781FB0912200B6C3C8 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | BD8FA1721FB0912200B6C3C8 = { 41 | isa = PBXGroup; 42 | children = ( 43 | BD8FA17D1FB0912200B6C3C8 /* DragAndDropInCollectionView */, 44 | BD8FA17C1FB0912200B6C3C8 /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | BD8FA17C1FB0912200B6C3C8 /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | BD8FA17B1FB0912200B6C3C8 /* DragAndDropInCollectionView.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | BD8FA17D1FB0912200B6C3C8 /* DragAndDropInCollectionView */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | BD8FA17E1FB0912200B6C3C8 /* AppDelegate.swift */, 60 | BD8FA1801FB0912200B6C3C8 /* DragDropViewController.swift */, 61 | BDA631AB1FB31A3700A9DCF6 /* DragDropCollectionViewCell.swift */, 62 | BD8FA1821FB0912200B6C3C8 /* Main.storyboard */, 63 | BD8FA1851FB0912200B6C3C8 /* Assets.xcassets */, 64 | BD8FA1871FB0912200B6C3C8 /* LaunchScreen.storyboard */, 65 | BD8FA18A1FB0912200B6C3C8 /* Info.plist */, 66 | ); 67 | path = DragAndDropInCollectionView; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | BD8FA17A1FB0912200B6C3C8 /* DragAndDropInCollectionView */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = BD8FA18D1FB0912200B6C3C8 /* Build configuration list for PBXNativeTarget "DragAndDropInCollectionView" */; 76 | buildPhases = ( 77 | BD8FA1771FB0912200B6C3C8 /* Sources */, 78 | BD8FA1781FB0912200B6C3C8 /* Frameworks */, 79 | BD8FA1791FB0912200B6C3C8 /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = DragAndDropInCollectionView; 86 | productName = DragAndDropInCollectionView; 87 | productReference = BD8FA17B1FB0912200B6C3C8 /* DragAndDropInCollectionView.app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | BD8FA1731FB0912200B6C3C8 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastSwiftUpdateCheck = 0910; 97 | LastUpgradeCheck = 0910; 98 | ORGANIZATIONNAME = "Payal Gupta"; 99 | TargetAttributes = { 100 | BD8FA17A1FB0912200B6C3C8 = { 101 | CreatedOnToolsVersion = 9.1; 102 | ProvisioningStyle = Automatic; 103 | }; 104 | }; 105 | }; 106 | buildConfigurationList = BD8FA1761FB0912200B6C3C8 /* Build configuration list for PBXProject "DragAndDropInCollectionView" */; 107 | compatibilityVersion = "Xcode 8.0"; 108 | developmentRegion = en; 109 | hasScannedForEncodings = 0; 110 | knownRegions = ( 111 | en, 112 | Base, 113 | ); 114 | mainGroup = BD8FA1721FB0912200B6C3C8; 115 | productRefGroup = BD8FA17C1FB0912200B6C3C8 /* Products */; 116 | projectDirPath = ""; 117 | projectRoot = ""; 118 | targets = ( 119 | BD8FA17A1FB0912200B6C3C8 /* DragAndDropInCollectionView */, 120 | ); 121 | }; 122 | /* End PBXProject section */ 123 | 124 | /* Begin PBXResourcesBuildPhase section */ 125 | BD8FA1791FB0912200B6C3C8 /* Resources */ = { 126 | isa = PBXResourcesBuildPhase; 127 | buildActionMask = 2147483647; 128 | files = ( 129 | BD8FA1891FB0912200B6C3C8 /* LaunchScreen.storyboard in Resources */, 130 | BD8FA1861FB0912200B6C3C8 /* Assets.xcassets in Resources */, 131 | BD8FA1841FB0912200B6C3C8 /* Main.storyboard in Resources */, 132 | ); 133 | runOnlyForDeploymentPostprocessing = 0; 134 | }; 135 | /* End PBXResourcesBuildPhase section */ 136 | 137 | /* Begin PBXSourcesBuildPhase section */ 138 | BD8FA1771FB0912200B6C3C8 /* Sources */ = { 139 | isa = PBXSourcesBuildPhase; 140 | buildActionMask = 2147483647; 141 | files = ( 142 | BD8FA1811FB0912200B6C3C8 /* DragDropViewController.swift in Sources */, 143 | BDA631AC1FB31A3700A9DCF6 /* DragDropCollectionViewCell.swift in Sources */, 144 | BD8FA17F1FB0912200B6C3C8 /* AppDelegate.swift in Sources */, 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | /* End PBXSourcesBuildPhase section */ 149 | 150 | /* Begin PBXVariantGroup section */ 151 | BD8FA1821FB0912200B6C3C8 /* Main.storyboard */ = { 152 | isa = PBXVariantGroup; 153 | children = ( 154 | BD8FA1831FB0912200B6C3C8 /* Base */, 155 | ); 156 | name = Main.storyboard; 157 | sourceTree = ""; 158 | }; 159 | BD8FA1871FB0912200B6C3C8 /* LaunchScreen.storyboard */ = { 160 | isa = PBXVariantGroup; 161 | children = ( 162 | BD8FA1881FB0912200B6C3C8 /* Base */, 163 | ); 164 | name = LaunchScreen.storyboard; 165 | sourceTree = ""; 166 | }; 167 | /* End PBXVariantGroup section */ 168 | 169 | /* Begin XCBuildConfiguration section */ 170 | BD8FA18B1FB0912200B6C3C8 /* Debug */ = { 171 | isa = XCBuildConfiguration; 172 | buildSettings = { 173 | ALWAYS_SEARCH_USER_PATHS = NO; 174 | CLANG_ANALYZER_NONNULL = YES; 175 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 176 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 177 | CLANG_CXX_LIBRARY = "libc++"; 178 | CLANG_ENABLE_MODULES = YES; 179 | CLANG_ENABLE_OBJC_ARC = YES; 180 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 181 | CLANG_WARN_BOOL_CONVERSION = YES; 182 | CLANG_WARN_COMMA = YES; 183 | CLANG_WARN_CONSTANT_CONVERSION = YES; 184 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 185 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 186 | CLANG_WARN_EMPTY_BODY = YES; 187 | CLANG_WARN_ENUM_CONVERSION = YES; 188 | CLANG_WARN_INFINITE_RECURSION = YES; 189 | CLANG_WARN_INT_CONVERSION = YES; 190 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 191 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 192 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 193 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 194 | CLANG_WARN_STRICT_PROTOTYPES = YES; 195 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 196 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 197 | CLANG_WARN_UNREACHABLE_CODE = YES; 198 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 199 | CODE_SIGN_IDENTITY = "iPhone Developer"; 200 | COPY_PHASE_STRIP = NO; 201 | DEBUG_INFORMATION_FORMAT = dwarf; 202 | ENABLE_STRICT_OBJC_MSGSEND = YES; 203 | ENABLE_TESTABILITY = YES; 204 | GCC_C_LANGUAGE_STANDARD = gnu11; 205 | GCC_DYNAMIC_NO_PIC = NO; 206 | GCC_NO_COMMON_BLOCKS = YES; 207 | GCC_OPTIMIZATION_LEVEL = 0; 208 | GCC_PREPROCESSOR_DEFINITIONS = ( 209 | "DEBUG=1", 210 | "$(inherited)", 211 | ); 212 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 213 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 214 | GCC_WARN_UNDECLARED_SELECTOR = YES; 215 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 216 | GCC_WARN_UNUSED_FUNCTION = YES; 217 | GCC_WARN_UNUSED_VARIABLE = YES; 218 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 219 | MTL_ENABLE_DEBUG_INFO = YES; 220 | ONLY_ACTIVE_ARCH = YES; 221 | SDKROOT = iphoneos; 222 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 223 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 224 | }; 225 | name = Debug; 226 | }; 227 | BD8FA18C1FB0912200B6C3C8 /* Release */ = { 228 | isa = XCBuildConfiguration; 229 | buildSettings = { 230 | ALWAYS_SEARCH_USER_PATHS = NO; 231 | CLANG_ANALYZER_NONNULL = YES; 232 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 233 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 234 | CLANG_CXX_LIBRARY = "libc++"; 235 | CLANG_ENABLE_MODULES = YES; 236 | CLANG_ENABLE_OBJC_ARC = YES; 237 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 238 | CLANG_WARN_BOOL_CONVERSION = YES; 239 | CLANG_WARN_COMMA = YES; 240 | CLANG_WARN_CONSTANT_CONVERSION = 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_LITERAL_CONVERSION = YES; 249 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 250 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 251 | CLANG_WARN_STRICT_PROTOTYPES = YES; 252 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 253 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | CODE_SIGN_IDENTITY = "iPhone Developer"; 257 | COPY_PHASE_STRIP = NO; 258 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 259 | ENABLE_NS_ASSERTIONS = NO; 260 | ENABLE_STRICT_OBJC_MSGSEND = YES; 261 | GCC_C_LANGUAGE_STANDARD = gnu11; 262 | GCC_NO_COMMON_BLOCKS = YES; 263 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 264 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 265 | GCC_WARN_UNDECLARED_SELECTOR = YES; 266 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 267 | GCC_WARN_UNUSED_FUNCTION = YES; 268 | GCC_WARN_UNUSED_VARIABLE = YES; 269 | IPHONEOS_DEPLOYMENT_TARGET = 11.1; 270 | MTL_ENABLE_DEBUG_INFO = NO; 271 | SDKROOT = iphoneos; 272 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 273 | VALIDATE_PRODUCT = YES; 274 | }; 275 | name = Release; 276 | }; 277 | BD8FA18E1FB0912200B6C3C8 /* Debug */ = { 278 | isa = XCBuildConfiguration; 279 | buildSettings = { 280 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 281 | CODE_SIGN_STYLE = Automatic; 282 | DEVELOPMENT_TEAM = 295M57239Z; 283 | INFOPLIST_FILE = DragAndDropInCollectionView/Info.plist; 284 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 285 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 286 | PRODUCT_BUNDLE_IDENTIFIER = com.payal.DragAndDropInCollectionView; 287 | PRODUCT_NAME = "$(TARGET_NAME)"; 288 | SWIFT_VERSION = 4.0; 289 | TARGETED_DEVICE_FAMILY = "1,2"; 290 | }; 291 | name = Debug; 292 | }; 293 | BD8FA18F1FB0912200B6C3C8 /* Release */ = { 294 | isa = XCBuildConfiguration; 295 | buildSettings = { 296 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 297 | CODE_SIGN_STYLE = Automatic; 298 | DEVELOPMENT_TEAM = 295M57239Z; 299 | INFOPLIST_FILE = DragAndDropInCollectionView/Info.plist; 300 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 301 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 302 | PRODUCT_BUNDLE_IDENTIFIER = com.payal.DragAndDropInCollectionView; 303 | PRODUCT_NAME = "$(TARGET_NAME)"; 304 | SWIFT_VERSION = 4.0; 305 | TARGETED_DEVICE_FAMILY = "1,2"; 306 | }; 307 | name = Release; 308 | }; 309 | /* End XCBuildConfiguration section */ 310 | 311 | /* Begin XCConfigurationList section */ 312 | BD8FA1761FB0912200B6C3C8 /* Build configuration list for PBXProject "DragAndDropInCollectionView" */ = { 313 | isa = XCConfigurationList; 314 | buildConfigurations = ( 315 | BD8FA18B1FB0912200B6C3C8 /* Debug */, 316 | BD8FA18C1FB0912200B6C3C8 /* Release */, 317 | ); 318 | defaultConfigurationIsVisible = 0; 319 | defaultConfigurationName = Release; 320 | }; 321 | BD8FA18D1FB0912200B6C3C8 /* Build configuration list for PBXNativeTarget "DragAndDropInCollectionView" */ = { 322 | isa = XCConfigurationList; 323 | buildConfigurations = ( 324 | BD8FA18E1FB0912200B6C3C8 /* Debug */, 325 | BD8FA18F1FB0912200B6C3C8 /* Release */, 326 | ); 327 | defaultConfigurationIsVisible = 0; 328 | defaultConfigurationName = Release; 329 | }; 330 | /* End XCConfigurationList section */ 331 | }; 332 | rootObject = BD8FA1731FB0912200B6C3C8 /* Project object */; 333 | } 334 | -------------------------------------------------------------------------------- /DragAndDropInCollectionView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DragAndDropInCollectionView.xcodeproj/xcuserdata/payalgupta.xcuserdatad/xcschemes/DragAndDropInCollectionView.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /DragAndDropInCollectionView.xcodeproj/xcuserdata/payalgupta.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DragAndDropInCollectionView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | BD8FA17A1FB0912200B6C3C8 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /DragAndDropInCollectionView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // DragAndDropInCollectionView 4 | // 5 | // Created by Payal Gupta on 06/11/17. 6 | // Copyright © 2017 Payal Gupta. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /DragAndDropInCollectionView/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 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/chrome.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "chrome.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/chrome.imageset/chrome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/chrome.imageset/chrome.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/fade.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "fade.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/fade.imageset/fade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/fade.imageset/fade.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/falseColor.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "falseColor.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/falseColor.imageset/falseColor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/falseColor.imageset/falseColor.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/instant.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "instant.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/instant.imageset/instant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/instant.imageset/instant.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/mono.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "mono.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/mono.imageset/mono.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/mono.imageset/mono.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/noir.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "noir.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/noir.imageset/noir.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/noir.imageset/noir.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/none.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "none.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/none.imageset/none.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/none.imageset/none.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/pin.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "thumbtack-pushpin-2-hi.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/pin.imageset/thumbtack-pushpin-2-hi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/pin.imageset/thumbtack-pushpin-2-hi.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/process.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "process.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/process.imageset/process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/process.imageset/process.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/sepia.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "sepia.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/sepia.imageset/sepia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/sepia.imageset/sepia.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/texture.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "grunge-texture-abstract-hd-wallpaper-2560x1440-8066.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/texture.imageset/grunge-texture-abstract-hd-wallpaper-2560x1440-8066.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/texture.imageset/grunge-texture-abstract-hd-wallpaper-2560x1440-8066.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/tonal.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "tonal.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/tonal.imageset/tonal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/tonal.imageset/tonal.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/transfer.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "transfer.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Assets.xcassets/transfer.imageset/transfer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragAndDropInCollectionView/Assets.xcassets/transfer.imageset/transfer.png -------------------------------------------------------------------------------- /DragAndDropInCollectionView/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 | -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | AvenirNext-DemiBold 15 | AvenirNext-DemiBoldItalic 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 60 | 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 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | -------------------------------------------------------------------------------- /DragAndDropInCollectionView/DragDropCollectionViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DragDropCollectionViewCell.swift 3 | // DragAndDropInCollectionView 4 | // 5 | // Created by Payal Gupta on 08/11/17. 6 | // Copyright © 2017 Payal Gupta. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DragDropCollectionViewCell: UICollectionViewCell 12 | { 13 | @IBOutlet weak var customImageView: UIImageView! 14 | @IBOutlet weak var customLabel: UILabel! 15 | } 16 | -------------------------------------------------------------------------------- /DragAndDropInCollectionView/DragDropViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DragDropViewController.swift 3 | // DragAndDropInCollectionView 4 | // 5 | // Created by Payal Gupta on 06/11/17. 6 | // Copyright © 2017 Payal Gupta. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DragDropViewController: UIViewController 12 | { 13 | //MARK: Private Properties 14 | //Data Source for CollectionView-1 15 | private var items1 = ["none", "chrome", "fade", "falseColor", "instant", "mono", "noir", "process", "sepia", "tonal", "transfer"] 16 | 17 | //Data Source for CollectionView-2 18 | private var items2 = [String]() 19 | 20 | //MARK: Outlets 21 | @IBOutlet weak var collectionView1: UICollectionView! 22 | @IBOutlet weak var collectionView2: UICollectionView! 23 | 24 | //MARK: View Lifecycle Methods 25 | override func viewDidLoad() 26 | { 27 | super.viewDidLoad() 28 | 29 | //CollectionView-1 drag and drop configuration 30 | self.collectionView1.dragInteractionEnabled = true 31 | self.collectionView1.dragDelegate = self 32 | self.collectionView1.dropDelegate = self 33 | 34 | //CollectionView-2 drag and drop configuration 35 | self.collectionView2.dragInteractionEnabled = true 36 | self.collectionView2.dropDelegate = self 37 | self.collectionView2.dragDelegate = self 38 | self.collectionView2.reorderingCadence = .fast //default value - .immediate 39 | } 40 | 41 | //MARK: Private Methods 42 | 43 | /// This method moves a cell from source indexPath to destination indexPath within the same collection view. It works for only 1 item. If multiple items selected, no reordering happens. 44 | /// 45 | /// - Parameters: 46 | /// - coordinator: coordinator obtained from performDropWith: UICollectionViewDropDelegate method 47 | /// - destinationIndexPath: indexpath of the collection view where the user drops the element 48 | /// - collectionView: collectionView in which reordering needs to be done. 49 | private func reorderItems(coordinator: UICollectionViewDropCoordinator, destinationIndexPath: IndexPath, collectionView: UICollectionView) 50 | { 51 | let items = coordinator.items 52 | if items.count == 1, let item = items.first, let sourceIndexPath = item.sourceIndexPath 53 | { 54 | var dIndexPath = destinationIndexPath 55 | if dIndexPath.row >= collectionView.numberOfItems(inSection: 0) 56 | { 57 | dIndexPath.row = collectionView.numberOfItems(inSection: 0) - 1 58 | } 59 | collectionView.performBatchUpdates({ 60 | if collectionView === self.collectionView2 61 | { 62 | self.items2.remove(at: sourceIndexPath.row) 63 | self.items2.insert(item.dragItem.localObject as! String, at: dIndexPath.row) 64 | } 65 | else 66 | { 67 | self.items1.remove(at: sourceIndexPath.row) 68 | self.items1.insert(item.dragItem.localObject as! String, at: dIndexPath.row) 69 | } 70 | collectionView.deleteItems(at: [sourceIndexPath]) 71 | collectionView.insertItems(at: [dIndexPath]) 72 | }) 73 | coordinator.drop(items.first!.dragItem, toItemAt: dIndexPath) 74 | } 75 | } 76 | 77 | /// This method copies a cell from source indexPath in 1st collection view to destination indexPath in 2nd collection view. It works for multiple items. 78 | /// 79 | /// - Parameters: 80 | /// - coordinator: coordinator obtained from performDropWith: UICollectionViewDropDelegate method 81 | /// - destinationIndexPath: indexpath of the collection view where the user drops the element 82 | /// - collectionView: collectionView in which reordering needs to be done. 83 | private func copyItems(coordinator: UICollectionViewDropCoordinator, destinationIndexPath: IndexPath, collectionView: UICollectionView) 84 | { 85 | collectionView.performBatchUpdates({ 86 | var indexPaths = [IndexPath]() 87 | for (index, item) in coordinator.items.enumerated() 88 | { 89 | let indexPath = IndexPath(row: destinationIndexPath.row + index, section: destinationIndexPath.section) 90 | if collectionView === self.collectionView2 91 | { 92 | self.items2.insert(item.dragItem.localObject as! String, at: indexPath.row) 93 | } 94 | else 95 | { 96 | self.items1.insert(item.dragItem.localObject as! String, at: indexPath.row) 97 | } 98 | indexPaths.append(indexPath) 99 | } 100 | collectionView.insertItems(at: indexPaths) 101 | }) 102 | } 103 | } 104 | 105 | // MARK: - UICollectionViewDataSource Methods 106 | extension DragDropViewController : UICollectionViewDataSource 107 | { 108 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int 109 | { 110 | return collectionView == self.collectionView1 ? self.items1.count : self.items2.count 111 | } 112 | 113 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell 114 | { 115 | if collectionView == self.collectionView1 116 | { 117 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell1", for: indexPath) as! DragDropCollectionViewCell 118 | cell.customImageView?.image = UIImage(named: self.items1[indexPath.row]) 119 | cell.customLabel.text = self.items1[indexPath.row].capitalized 120 | return cell 121 | } 122 | else 123 | { 124 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell2", for: indexPath) as! DragDropCollectionViewCell 125 | cell.customImageView?.image = UIImage(named: self.items2[indexPath.row]) 126 | cell.customLabel.text = self.items2[indexPath.row].capitalized 127 | return cell 128 | } 129 | } 130 | } 131 | 132 | // MARK: - UICollectionViewDragDelegate Methods 133 | extension DragDropViewController : UICollectionViewDragDelegate 134 | { 135 | func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] 136 | { 137 | let item = collectionView == collectionView1 ? self.items1[indexPath.row] : self.items2[indexPath.row] 138 | let itemProvider = NSItemProvider(object: item as NSString) 139 | let dragItem = UIDragItem(itemProvider: itemProvider) 140 | dragItem.localObject = item 141 | return [dragItem] 142 | } 143 | 144 | func collectionView(_ collectionView: UICollectionView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] 145 | { 146 | let item = collectionView == collectionView1 ? self.items1[indexPath.row] : self.items2[indexPath.row] 147 | let itemProvider = NSItemProvider(object: item as NSString) 148 | let dragItem = UIDragItem(itemProvider: itemProvider) 149 | dragItem.localObject = item 150 | return [dragItem] 151 | } 152 | 153 | func collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath) -> UIDragPreviewParameters? 154 | { 155 | if collectionView == collectionView1 156 | { 157 | let previewParameters = UIDragPreviewParameters() 158 | previewParameters.visiblePath = UIBezierPath(rect: CGRect(x: 25, y: 25, width: 120, height: 120)) 159 | return previewParameters 160 | } 161 | return nil 162 | } 163 | } 164 | 165 | // MARK: - UICollectionViewDropDelegate Methods 166 | extension DragDropViewController : UICollectionViewDropDelegate 167 | { 168 | func collectionView(_ collectionView: UICollectionView, canHandle session: UIDropSession) -> Bool 169 | { 170 | return session.canLoadObjects(ofClass: NSString.self) 171 | } 172 | 173 | func collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposal 174 | { 175 | if collectionView === self.collectionView1 176 | { 177 | if collectionView.hasActiveDrag 178 | { 179 | return UICollectionViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath) 180 | } 181 | else 182 | { 183 | return UICollectionViewDropProposal(operation: .forbidden) 184 | } 185 | } 186 | else 187 | { 188 | if collectionView.hasActiveDrag 189 | { 190 | return UICollectionViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath) 191 | } 192 | else 193 | { 194 | return UICollectionViewDropProposal(operation: .copy, intent: .insertAtDestinationIndexPath) 195 | } 196 | } 197 | } 198 | 199 | func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator) 200 | { 201 | let destinationIndexPath: IndexPath 202 | if let indexPath = coordinator.destinationIndexPath 203 | { 204 | destinationIndexPath = indexPath 205 | } 206 | else 207 | { 208 | // Get last index path of table view. 209 | let section = collectionView.numberOfSections - 1 210 | let row = collectionView.numberOfItems(inSection: section) 211 | destinationIndexPath = IndexPath(row: row, section: section) 212 | } 213 | 214 | switch coordinator.proposal.operation 215 | { 216 | case .move: 217 | self.reorderItems(coordinator: coordinator, destinationIndexPath:destinationIndexPath, collectionView: collectionView) 218 | break 219 | 220 | case .copy: 221 | self.copyItems(coordinator: coordinator, destinationIndexPath: destinationIndexPath, collectionView: collectionView) 222 | 223 | default: 224 | return 225 | } 226 | } 227 | } 228 | 229 | -------------------------------------------------------------------------------- /DragAndDropInCollectionView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | DragDrop 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 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /DragDrop.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pgpt10/DragAndDrop-CollectionView/496ddaf293c531bc7e0372552f2fa407650d8215/DragDrop.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Payal Gupta 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DragAndDrop-CollectionView 2 | 3 | With the release of iOS-11, Apple introduced Drag and Drop in UITableView and UICollection with a specialized API that works on the concept of Interactions (something like gestures). 4 | 5 | UITableView and UICollectionView have similar APIs to support Drag and Drop with some small differences. So, in this sample I'll be showing how you can integrate drag and drop in UICollectionView. 6 | 7 | ## Preview 8 | Preview gif 9 | 10 | ## Implementation Details 11 | 12 | Here you can find the complete implementation details of drag & drop in table view and collection view. 13 | 14 | ## What's in the project? 15 | 16 | ### This project provides Drag and Drop support in: 17 | 1. iPhone (In iPhone, Drag and Drop is supported only in the same app. In iPad, Drag and Drop is supported within multiple apps.) 18 | 2. iOS 11 19 | 3. Swift 4 20 | 4. UICollectionView 21 | 22 | ### Project Describes: 23 | 1. UICollectionViewDragDelegate and UICollectionViewDropDelegate to support Drag and Drop in UICollectionView. 24 | 2. Reordering cells in UICollectionView. 25 | 3. Controlling drag speed while reordering - reorderingCadence. 26 | 4. Copying data within multiple Collection Views. 27 | 5. Dragging and dropping single as well as multiple items. 28 | 6. What the element looks like when it is dragged around - Drag Preview. 29 | 7. How to handle drops i.e. copy/move/cancel/forbidden - Drop Proposal. 30 | 8. Performing actual drop in same/different UICollectionView. 31 | 32 | ## Project Details 33 | The project describes Drag and Drop using 2 UICollectionViews and supports: 34 | 1. Reordering - Moving an element from source to destination indexpath within same Collection View. 35 | 2. Copying an element from 1st Collection View to 2nd CollectionView at a particular destination indexpath. 36 | 3. Forbidding the movement(copying/moving) of an element from 2nd Collection View to 1st CollectionView. 37 | --------------------------------------------------------------------------------