├── .gitignore ├── MQImageDragView.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── macpro.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── macpro.xcuserdatad │ └── xcschemes │ ├── MQImageDragView.xcscheme │ └── xcschememanagement.plist ├── MQImageDragView ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── add.imageset │ │ ├── Contents.json │ │ └── add@2x.png │ ├── buttton_image1.imageset │ │ ├── Contents.json │ │ └── buttton_image1.png │ ├── buttton_image2.imageset │ │ ├── Contents.json │ │ └── buttton_image2.png │ ├── buttton_image3.imageset │ │ ├── Contents.json │ │ └── buttton_image3.png │ └── delete.imageset │ │ ├── Contents.json │ │ └── delete@2x.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── MQImageDragView │ ├── MQImageButton.h │ ├── MQImageButton.m │ ├── MQImageDragView.h │ └── MQImageDragView.m ├── TestTableViewCell.h ├── TestTableViewCell.m ├── ViewController.h ├── ViewController.m └── main.m └── README.md /.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 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | -------------------------------------------------------------------------------- /MQImageDragView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8ECDBC7F1CDC268900F191D2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8ECDBC7E1CDC268900F191D2 /* main.m */; }; 11 | 8ECDBC821CDC268900F191D2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8ECDBC811CDC268900F191D2 /* AppDelegate.m */; }; 12 | 8ECDBC881CDC268900F191D2 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8ECDBC861CDC268900F191D2 /* Main.storyboard */; }; 13 | 8ECDBC8A1CDC268900F191D2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8ECDBC891CDC268900F191D2 /* Assets.xcassets */; }; 14 | 8ECDBC8D1CDC268900F191D2 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8ECDBC8B1CDC268900F191D2 /* LaunchScreen.storyboard */; }; 15 | 8ECDBC9D1CDC26B400F191D2 /* MQImageButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 8ECDBC961CDC26B400F191D2 /* MQImageButton.m */; }; 16 | 8ECDBC9E1CDC26B400F191D2 /* MQImageDragView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8ECDBC981CDC26B400F191D2 /* MQImageDragView.m */; }; 17 | 8ECDBC9F1CDC26B400F191D2 /* TestTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8ECDBC9A1CDC26B400F191D2 /* TestTableViewCell.m */; }; 18 | 8ECDBCA01CDC26B400F191D2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8ECDBC9C1CDC26B400F191D2 /* ViewController.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 8ECDBC7A1CDC268900F191D2 /* MQImageDragView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MQImageDragView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 8ECDBC7E1CDC268900F191D2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 24 | 8ECDBC801CDC268900F191D2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 25 | 8ECDBC811CDC268900F191D2 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 26 | 8ECDBC871CDC268900F191D2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | 8ECDBC891CDC268900F191D2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | 8ECDBC8C1CDC268900F191D2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | 8ECDBC8E1CDC268900F191D2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 8ECDBC951CDC26B400F191D2 /* MQImageButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MQImageButton.h; sourceTree = ""; }; 31 | 8ECDBC961CDC26B400F191D2 /* MQImageButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MQImageButton.m; sourceTree = ""; }; 32 | 8ECDBC971CDC26B400F191D2 /* MQImageDragView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MQImageDragView.h; sourceTree = ""; }; 33 | 8ECDBC981CDC26B400F191D2 /* MQImageDragView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MQImageDragView.m; sourceTree = ""; }; 34 | 8ECDBC991CDC26B400F191D2 /* TestTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestTableViewCell.h; sourceTree = ""; }; 35 | 8ECDBC9A1CDC26B400F191D2 /* TestTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestTableViewCell.m; sourceTree = ""; }; 36 | 8ECDBC9B1CDC26B400F191D2 /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 37 | 8ECDBC9C1CDC26B400F191D2 /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 38 | /* End PBXFileReference section */ 39 | 40 | /* Begin PBXFrameworksBuildPhase section */ 41 | 8ECDBC771CDC268900F191D2 /* Frameworks */ = { 42 | isa = PBXFrameworksBuildPhase; 43 | buildActionMask = 2147483647; 44 | files = ( 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | /* End PBXFrameworksBuildPhase section */ 49 | 50 | /* Begin PBXGroup section */ 51 | 8ECDBC711CDC268900F191D2 = { 52 | isa = PBXGroup; 53 | children = ( 54 | 8ECDBC7C1CDC268900F191D2 /* MQImageDragView */, 55 | 8ECDBC7B1CDC268900F191D2 /* Products */, 56 | ); 57 | sourceTree = ""; 58 | }; 59 | 8ECDBC7B1CDC268900F191D2 /* Products */ = { 60 | isa = PBXGroup; 61 | children = ( 62 | 8ECDBC7A1CDC268900F191D2 /* MQImageDragView.app */, 63 | ); 64 | name = Products; 65 | sourceTree = ""; 66 | }; 67 | 8ECDBC7C1CDC268900F191D2 /* MQImageDragView */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | 8ECDBC801CDC268900F191D2 /* AppDelegate.h */, 71 | 8ECDBC811CDC268900F191D2 /* AppDelegate.m */, 72 | 8ECDBC9B1CDC26B400F191D2 /* ViewController.h */, 73 | 8ECDBC9C1CDC26B400F191D2 /* ViewController.m */, 74 | 8ECDBC991CDC26B400F191D2 /* TestTableViewCell.h */, 75 | 8ECDBC9A1CDC26B400F191D2 /* TestTableViewCell.m */, 76 | 8ECDBC941CDC26B400F191D2 /* MQImageDragView */, 77 | 8ECDBC7D1CDC268900F191D2 /* Supporting Files */, 78 | ); 79 | path = MQImageDragView; 80 | sourceTree = ""; 81 | }; 82 | 8ECDBC7D1CDC268900F191D2 /* Supporting Files */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 8ECDBC861CDC268900F191D2 /* Main.storyboard */, 86 | 8ECDBC891CDC268900F191D2 /* Assets.xcassets */, 87 | 8ECDBC8B1CDC268900F191D2 /* LaunchScreen.storyboard */, 88 | 8ECDBC8E1CDC268900F191D2 /* Info.plist */, 89 | 8ECDBC7E1CDC268900F191D2 /* main.m */, 90 | ); 91 | name = "Supporting Files"; 92 | sourceTree = ""; 93 | }; 94 | 8ECDBC941CDC26B400F191D2 /* MQImageDragView */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 8ECDBC951CDC26B400F191D2 /* MQImageButton.h */, 98 | 8ECDBC961CDC26B400F191D2 /* MQImageButton.m */, 99 | 8ECDBC971CDC26B400F191D2 /* MQImageDragView.h */, 100 | 8ECDBC981CDC26B400F191D2 /* MQImageDragView.m */, 101 | ); 102 | path = MQImageDragView; 103 | sourceTree = ""; 104 | }; 105 | /* End PBXGroup section */ 106 | 107 | /* Begin PBXNativeTarget section */ 108 | 8ECDBC791CDC268900F191D2 /* MQImageDragView */ = { 109 | isa = PBXNativeTarget; 110 | buildConfigurationList = 8ECDBC911CDC268900F191D2 /* Build configuration list for PBXNativeTarget "MQImageDragView" */; 111 | buildPhases = ( 112 | 8ECDBC761CDC268900F191D2 /* Sources */, 113 | 8ECDBC771CDC268900F191D2 /* Frameworks */, 114 | 8ECDBC781CDC268900F191D2 /* Resources */, 115 | ); 116 | buildRules = ( 117 | ); 118 | dependencies = ( 119 | ); 120 | name = MQImageDragView; 121 | productName = MQImageDragView; 122 | productReference = 8ECDBC7A1CDC268900F191D2 /* MQImageDragView.app */; 123 | productType = "com.apple.product-type.application"; 124 | }; 125 | /* End PBXNativeTarget section */ 126 | 127 | /* Begin PBXProject section */ 128 | 8ECDBC721CDC268900F191D2 /* Project object */ = { 129 | isa = PBXProject; 130 | attributes = { 131 | LastUpgradeCheck = 0730; 132 | ORGANIZATIONNAME = silvrunrun; 133 | TargetAttributes = { 134 | 8ECDBC791CDC268900F191D2 = { 135 | CreatedOnToolsVersion = 7.3; 136 | }; 137 | }; 138 | }; 139 | buildConfigurationList = 8ECDBC751CDC268900F191D2 /* Build configuration list for PBXProject "MQImageDragView" */; 140 | compatibilityVersion = "Xcode 3.2"; 141 | developmentRegion = English; 142 | hasScannedForEncodings = 0; 143 | knownRegions = ( 144 | en, 145 | Base, 146 | ); 147 | mainGroup = 8ECDBC711CDC268900F191D2; 148 | productRefGroup = 8ECDBC7B1CDC268900F191D2 /* Products */; 149 | projectDirPath = ""; 150 | projectRoot = ""; 151 | targets = ( 152 | 8ECDBC791CDC268900F191D2 /* MQImageDragView */, 153 | ); 154 | }; 155 | /* End PBXProject section */ 156 | 157 | /* Begin PBXResourcesBuildPhase section */ 158 | 8ECDBC781CDC268900F191D2 /* Resources */ = { 159 | isa = PBXResourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | 8ECDBC8D1CDC268900F191D2 /* LaunchScreen.storyboard in Resources */, 163 | 8ECDBC8A1CDC268900F191D2 /* Assets.xcassets in Resources */, 164 | 8ECDBC881CDC268900F191D2 /* Main.storyboard in Resources */, 165 | ); 166 | runOnlyForDeploymentPostprocessing = 0; 167 | }; 168 | /* End PBXResourcesBuildPhase section */ 169 | 170 | /* Begin PBXSourcesBuildPhase section */ 171 | 8ECDBC761CDC268900F191D2 /* Sources */ = { 172 | isa = PBXSourcesBuildPhase; 173 | buildActionMask = 2147483647; 174 | files = ( 175 | 8ECDBCA01CDC26B400F191D2 /* ViewController.m in Sources */, 176 | 8ECDBC9D1CDC26B400F191D2 /* MQImageButton.m in Sources */, 177 | 8ECDBC9F1CDC26B400F191D2 /* TestTableViewCell.m in Sources */, 178 | 8ECDBC821CDC268900F191D2 /* AppDelegate.m in Sources */, 179 | 8ECDBC9E1CDC26B400F191D2 /* MQImageDragView.m in Sources */, 180 | 8ECDBC7F1CDC268900F191D2 /* main.m in Sources */, 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | }; 184 | /* End PBXSourcesBuildPhase section */ 185 | 186 | /* Begin PBXVariantGroup section */ 187 | 8ECDBC861CDC268900F191D2 /* Main.storyboard */ = { 188 | isa = PBXVariantGroup; 189 | children = ( 190 | 8ECDBC871CDC268900F191D2 /* Base */, 191 | ); 192 | name = Main.storyboard; 193 | sourceTree = ""; 194 | }; 195 | 8ECDBC8B1CDC268900F191D2 /* LaunchScreen.storyboard */ = { 196 | isa = PBXVariantGroup; 197 | children = ( 198 | 8ECDBC8C1CDC268900F191D2 /* Base */, 199 | ); 200 | name = LaunchScreen.storyboard; 201 | sourceTree = ""; 202 | }; 203 | /* End PBXVariantGroup section */ 204 | 205 | /* Begin XCBuildConfiguration section */ 206 | 8ECDBC8F1CDC268900F191D2 /* Debug */ = { 207 | isa = XCBuildConfiguration; 208 | buildSettings = { 209 | ALWAYS_SEARCH_USER_PATHS = NO; 210 | CLANG_ANALYZER_NONNULL = YES; 211 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 212 | CLANG_CXX_LIBRARY = "libc++"; 213 | CLANG_ENABLE_MODULES = YES; 214 | CLANG_ENABLE_OBJC_ARC = YES; 215 | CLANG_WARN_BOOL_CONVERSION = YES; 216 | CLANG_WARN_CONSTANT_CONVERSION = YES; 217 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 218 | CLANG_WARN_EMPTY_BODY = YES; 219 | CLANG_WARN_ENUM_CONVERSION = YES; 220 | CLANG_WARN_INT_CONVERSION = YES; 221 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 222 | CLANG_WARN_UNREACHABLE_CODE = YES; 223 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 224 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 225 | COPY_PHASE_STRIP = NO; 226 | DEBUG_INFORMATION_FORMAT = dwarf; 227 | ENABLE_STRICT_OBJC_MSGSEND = YES; 228 | ENABLE_TESTABILITY = YES; 229 | GCC_C_LANGUAGE_STANDARD = gnu99; 230 | GCC_DYNAMIC_NO_PIC = NO; 231 | GCC_NO_COMMON_BLOCKS = YES; 232 | GCC_OPTIMIZATION_LEVEL = 0; 233 | GCC_PREPROCESSOR_DEFINITIONS = ( 234 | "DEBUG=1", 235 | "$(inherited)", 236 | ); 237 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 238 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 239 | GCC_WARN_UNDECLARED_SELECTOR = YES; 240 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 241 | GCC_WARN_UNUSED_FUNCTION = YES; 242 | GCC_WARN_UNUSED_VARIABLE = YES; 243 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 244 | MTL_ENABLE_DEBUG_INFO = YES; 245 | ONLY_ACTIVE_ARCH = YES; 246 | SDKROOT = iphoneos; 247 | }; 248 | name = Debug; 249 | }; 250 | 8ECDBC901CDC268900F191D2 /* Release */ = { 251 | isa = XCBuildConfiguration; 252 | buildSettings = { 253 | ALWAYS_SEARCH_USER_PATHS = NO; 254 | CLANG_ANALYZER_NONNULL = YES; 255 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 256 | CLANG_CXX_LIBRARY = "libc++"; 257 | CLANG_ENABLE_MODULES = YES; 258 | CLANG_ENABLE_OBJC_ARC = YES; 259 | CLANG_WARN_BOOL_CONVERSION = YES; 260 | CLANG_WARN_CONSTANT_CONVERSION = YES; 261 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 262 | CLANG_WARN_EMPTY_BODY = YES; 263 | CLANG_WARN_ENUM_CONVERSION = YES; 264 | CLANG_WARN_INT_CONVERSION = YES; 265 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 266 | CLANG_WARN_UNREACHABLE_CODE = YES; 267 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 268 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 269 | COPY_PHASE_STRIP = NO; 270 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 271 | ENABLE_NS_ASSERTIONS = NO; 272 | ENABLE_STRICT_OBJC_MSGSEND = YES; 273 | GCC_C_LANGUAGE_STANDARD = gnu99; 274 | GCC_NO_COMMON_BLOCKS = YES; 275 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 276 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 277 | GCC_WARN_UNDECLARED_SELECTOR = YES; 278 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 279 | GCC_WARN_UNUSED_FUNCTION = YES; 280 | GCC_WARN_UNUSED_VARIABLE = YES; 281 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 282 | MTL_ENABLE_DEBUG_INFO = NO; 283 | SDKROOT = iphoneos; 284 | VALIDATE_PRODUCT = YES; 285 | }; 286 | name = Release; 287 | }; 288 | 8ECDBC921CDC268900F191D2 /* Debug */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 292 | INFOPLIST_FILE = MQImageDragView/Info.plist; 293 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 294 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 295 | PRODUCT_BUNDLE_IDENTIFIER = com.silvrunrun.MQImageDragView; 296 | PRODUCT_NAME = "$(TARGET_NAME)"; 297 | }; 298 | name = Debug; 299 | }; 300 | 8ECDBC931CDC268900F191D2 /* Release */ = { 301 | isa = XCBuildConfiguration; 302 | buildSettings = { 303 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 304 | INFOPLIST_FILE = MQImageDragView/Info.plist; 305 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 306 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 307 | PRODUCT_BUNDLE_IDENTIFIER = com.silvrunrun.MQImageDragView; 308 | PRODUCT_NAME = "$(TARGET_NAME)"; 309 | }; 310 | name = Release; 311 | }; 312 | /* End XCBuildConfiguration section */ 313 | 314 | /* Begin XCConfigurationList section */ 315 | 8ECDBC751CDC268900F191D2 /* Build configuration list for PBXProject "MQImageDragView" */ = { 316 | isa = XCConfigurationList; 317 | buildConfigurations = ( 318 | 8ECDBC8F1CDC268900F191D2 /* Debug */, 319 | 8ECDBC901CDC268900F191D2 /* Release */, 320 | ); 321 | defaultConfigurationIsVisible = 0; 322 | defaultConfigurationName = Release; 323 | }; 324 | 8ECDBC911CDC268900F191D2 /* Build configuration list for PBXNativeTarget "MQImageDragView" */ = { 325 | isa = XCConfigurationList; 326 | buildConfigurations = ( 327 | 8ECDBC921CDC268900F191D2 /* Debug */, 328 | 8ECDBC931CDC268900F191D2 /* Release */, 329 | ); 330 | defaultConfigurationIsVisible = 0; 331 | }; 332 | /* End XCConfigurationList section */ 333 | }; 334 | rootObject = 8ECDBC721CDC268900F191D2 /* Project object */; 335 | } 336 | -------------------------------------------------------------------------------- /MQImageDragView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MQImageDragView.xcodeproj/project.xcworkspace/xcuserdata/macpro.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SilvRunrun/MQImageDragView/374a12aecd68e4a1e6bd8d274b06ce13180ab581/MQImageDragView.xcodeproj/project.xcworkspace/xcuserdata/macpro.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /MQImageDragView.xcodeproj/xcuserdata/macpro.xcuserdatad/xcschemes/MQImageDragView.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 | -------------------------------------------------------------------------------- /MQImageDragView.xcodeproj/xcuserdata/macpro.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | MQImageDragView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 8ECDBC791CDC268900F191D2 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /MQImageDragView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // MQImageDragView 4 | // 5 | // Created by ma on 16/5/6. 6 | // Copyright © 2016年 silvrunrun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /MQImageDragView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // MQImageDragView 4 | // 5 | // Created by ma on 16/5/6. 6 | // Copyright © 2016年 silvrunrun. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/add.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "add@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/add.imageset/add@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SilvRunrun/MQImageDragView/374a12aecd68e4a1e6bd8d274b06ce13180ab581/MQImageDragView/Assets.xcassets/add.imageset/add@2x.png -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/buttton_image1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "buttton_image1.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/buttton_image1.imageset/buttton_image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SilvRunrun/MQImageDragView/374a12aecd68e4a1e6bd8d274b06ce13180ab581/MQImageDragView/Assets.xcassets/buttton_image1.imageset/buttton_image1.png -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/buttton_image2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "buttton_image2.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/buttton_image2.imageset/buttton_image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SilvRunrun/MQImageDragView/374a12aecd68e4a1e6bd8d274b06ce13180ab581/MQImageDragView/Assets.xcassets/buttton_image2.imageset/buttton_image2.png -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/buttton_image3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "buttton_image3.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/buttton_image3.imageset/buttton_image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SilvRunrun/MQImageDragView/374a12aecd68e4a1e6bd8d274b06ce13180ab581/MQImageDragView/Assets.xcassets/buttton_image3.imageset/buttton_image3.png -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/delete.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "delete@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /MQImageDragView/Assets.xcassets/delete.imageset/delete@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SilvRunrun/MQImageDragView/374a12aecd68e4a1e6bd8d274b06ce13180ab581/MQImageDragView/Assets.xcassets/delete.imageset/delete@2x.png -------------------------------------------------------------------------------- /MQImageDragView/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 | -------------------------------------------------------------------------------- /MQImageDragView/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 | -------------------------------------------------------------------------------- /MQImageDragView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | 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 | 40 | 41 | -------------------------------------------------------------------------------- /MQImageDragView/MQImageDragView/MQImageButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // MQImageButton.h 3 | // MQImageDragView 4 | // 5 | // Created by ma on 16/1/25. 6 | // Copyright © 2016年 silvrunrun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MQImageButton : UIButton 12 | @property (nonatomic,copy) void(^deleteButtonClickedBlock)(); 13 | @property (nonatomic,copy) void(^buttonClickedBlock)(); 14 | @property (nonatomic,assign) BOOL isAddButton; 15 | - (BOOL)pointInDeleteButton:(CGPoint)point; 16 | @end 17 | -------------------------------------------------------------------------------- /MQImageDragView/MQImageDragView/MQImageButton.m: -------------------------------------------------------------------------------- 1 | // 2 | // MQImageButton.m 3 | // MQImageDragView 4 | // 5 | // Created by ma on 16/1/25. 6 | // Copyright © 2016年 silvrunrun. All rights reserved. 7 | // 8 | 9 | #import "MQImageButton.h" 10 | 11 | @interface MQImageButton () 12 | @property (nonatomic,strong) UIButton *deleteButton; 13 | @end 14 | 15 | @implementation MQImageButton 16 | - (instancetype)initWithFrame:(CGRect)frame{ 17 | self = [super initWithFrame:frame]; 18 | if (self) { 19 | //下面两句可以使image全屏显示在button上(self.imageView.contentMode没有用) 20 | self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill; 21 | self.contentVerticalAlignment = UIControlContentVerticalAlignmentFill; 22 | 23 | //删除按钮 24 | self.deleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; 25 | [self.deleteButton setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal]; 26 | [self.deleteButton addTarget:self action:@selector(deleteButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 27 | [self addSubview:self.deleteButton]; 28 | [self addTarget:self action:@selector(imageButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 29 | } 30 | return self; 31 | } 32 | 33 | - (void)layoutSubviews 34 | { 35 | [super layoutSubviews]; 36 | self.deleteButton.frame = CGRectMake(0, 0, 25, 25); 37 | } 38 | 39 | - (void)setIsAddButton:(BOOL)isAddButton{ 40 | _isAddButton = isAddButton; 41 | self.deleteButton.hidden = isAddButton; 42 | } 43 | 44 | - (void)deleteButtonClicked:(UIButton *)deleteButton 45 | { 46 | if (self.deleteButtonClickedBlock) { 47 | self.deleteButtonClickedBlock(); 48 | } 49 | } 50 | 51 | - (void)imageButtonClicked:(UIButton *)imageButton 52 | { 53 | if (self.buttonClickedBlock) { 54 | self.buttonClickedBlock(); 55 | } 56 | } 57 | 58 | - (BOOL)pointInDeleteButton:(CGPoint)point 59 | { 60 | return CGRectContainsPoint(self.deleteButton.frame, point); 61 | } 62 | @end 63 | -------------------------------------------------------------------------------- /MQImageDragView/MQImageDragView/MQImageDragView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MQImageDragView.h 3 | // MQImageDragView 4 | // 5 | // Created by ma on 16/1/25. 6 | // Copyright © 2016年 silvrunrun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol MQImageDragViewDelegate 12 | @optional 13 | /** 点击了添加按钮 */ 14 | - (void)imageDragViewAddButtonClicked; 15 | /** 点击了删除按钮 */ 16 | - (void)imageDragViewDeleteButtonClickedAtIndex:(NSInteger)index; 17 | /** 点击了按钮 */ 18 | - (void)imageDragViewButtonClickedAtIndex:(NSInteger)index; 19 | /** 移动了按钮 */ 20 | - (void)imageDragViewDidMoveButtonFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex; 21 | @end 22 | 23 | @interface MQImageDragView : UIScrollView 24 | @property (nonatomic,assign) CGFloat kCountInRow; //每行个数 25 | @property (nonatomic,assign) CGFloat kMarginLRTB; //上下左右间距 26 | @property (nonatomic,assign) CGFloat kMarginB; //按钮间距 27 | @property (nonatomic,assign) CGFloat kMaxCount; //最大数量 28 | 29 | /** 代理 */ 30 | @property (nonatomic,weak) id dragViewDelegete; 31 | /** 添加一张照片 */ 32 | - (void)addImage:(UIImage *)image; 33 | /** 获取所有照片 */ 34 | - (NSArray *)getAllImages; 35 | /** 获取所有按钮 */ 36 | - (NSArray *)getAllImageButtons; 37 | /** 获取本视图适当的高度 */ 38 | - (CGFloat)getHeightThatFit; 39 | @end 40 | -------------------------------------------------------------------------------- /MQImageDragView/MQImageDragView/MQImageDragView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MQImageDragView.m 3 | // MQImageDragView 4 | // 5 | // Created by ma on 16/1/25. 6 | // Copyright © 2016年 silvrunrun. All rights reserved. 7 | // 8 | 9 | #import "MQImageDragView.h" 10 | #import "MQImageButton.h" 11 | 12 | @interface MQImageDragView () 13 | @property (nonatomic,strong) MQImageButton *addButton; 14 | //所有的照片按钮 15 | @property (nonatomic,strong) NSMutableArray *allButtons; 16 | //开始移动时候按钮的坐标 17 | @property (nonatomic,assign) CGPoint startPointForLong; 18 | //上次移动时候按钮的中点 19 | @property (nonatomic,assign) CGPoint originCenterForLong; 20 | //被移动的按钮原始index 21 | @property (nonatomic,assign) NSInteger originIndex; 22 | @end 23 | 24 | @implementation MQImageDragView 25 | #pragma mark - init 26 | - (instancetype)initWithFrame:(CGRect)frame{ 27 | self = [super initWithFrame:frame]; 28 | if (self) { 29 | //初始化 30 | self.kCountInRow = 4; 31 | self.kMarginLRTB = 20; 32 | self.kMarginB = 15; 33 | self.kMaxCount = 16; 34 | 35 | //添加按钮 36 | self.addButton = [[MQImageButton alloc] initWithFrame:CGRectZero]; 37 | self.addButton.isAddButton = YES; 38 | [self.addButton setImage:[UIImage imageNamed:@"add"] forState:UIControlStateNormal]; 39 | __weak typeof(self) weakSelf = self; 40 | self.addButton.buttonClickedBlock = ^(){ 41 | if ([weakSelf.dragViewDelegete respondsToSelector:@selector(imageDragViewAddButtonClicked)]) { 42 | [weakSelf.dragViewDelegete imageDragViewAddButtonClicked]; 43 | } 44 | }; 45 | [self addSubview:self.addButton]; 46 | 47 | //所有照片按钮的数组 48 | self.allButtons = [NSMutableArray arrayWithObject:self.addButton]; 49 | 50 | //布局 51 | [self layoutAllButtonsExcept:nil animated:NO]; 52 | } 53 | return self; 54 | } 55 | 56 | #pragma mark - setter 57 | - (void)setKCountInRow:(CGFloat)kCountInRow{ 58 | _kCountInRow = kCountInRow; 59 | [self layoutAllButtonsExcept:nil animated:NO]; 60 | } 61 | 62 | - (void)setKMarginLRTB:(CGFloat)kMarginLRTB{ 63 | _kMarginLRTB = kMarginLRTB; 64 | [self layoutAllButtonsExcept:nil animated:NO]; 65 | } 66 | 67 | - (void)setKMarginB:(CGFloat)kMarginB{ 68 | _kMarginB = kMarginB; 69 | [self layoutAllButtonsExcept:nil animated:NO]; 70 | } 71 | 72 | - (void)setKMaxCount:(CGFloat)kMaxCount{ 73 | _kMaxCount = kMaxCount; 74 | [self layoutAllButtonsExcept:nil animated:NO]; 75 | } 76 | 77 | #pragma mark - getsture 78 | - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ 79 | //获取移动的按钮 80 | UIView *view = gestureRecognizer.view; 81 | if ([view isKindOfClass:[MQImageButton class]]) { 82 | MQImageButton *button = (MQImageButton *)gestureRecognizer.view; 83 | CGPoint point = [gestureRecognizer locationInView:button]; 84 | return ![button pointInDeleteButton:point]; 85 | } 86 | return YES; 87 | } 88 | 89 | - (void)longPressGestureRecognized:(UILongPressGestureRecognizer *)longPress 90 | { 91 | //获取移动的按钮 92 | MQImageButton *button = (MQImageButton *)longPress.view; 93 | [self bringSubviewToFront:button]; 94 | //获取移动差值 95 | CGPoint center = button.center; 96 | //判断添加按钮是否存在 97 | BOOL hasAddButton = [self.allButtons.lastObject isAddButton]; 98 | //手势开始 99 | switch (longPress.state) { 100 | case UIGestureRecognizerStateBegan:{ 101 | self.startPointForLong = [longPress locationInView:self]; 102 | self.originCenterForLong = center; 103 | [UIView animateWithDuration:0.2 animations:^{ 104 | CGFloat margin = 5; 105 | button.frame = CGRectMake(button.frame.origin.x-margin, button.frame.origin.y-margin, button.frame.size.width+2*margin, button.frame.size.height+2*margin); 106 | button.alpha = 0.7; 107 | }]; 108 | //获取原始index 109 | self.originIndex = [self.allButtons indexOfObject:button]; 110 | } 111 | break; 112 | case UIGestureRecognizerStateChanged:{ 113 | CGPoint newPoint = [longPress locationInView:self]; 114 | CGPoint center = self.originCenterForLong; 115 | center.x += newPoint.x-self.startPointForLong.x; 116 | center.y += newPoint.y-self.startPointForLong.y; 117 | button.center = center; 118 | 119 | NSInteger countInRow = self.kCountInRow; 120 | CGFloat marginLRTB = self.kMarginLRTB; 121 | CGFloat marginB = self.kMarginB; 122 | CGFloat viewW = self.frame.size.width; 123 | //计算更新位置 124 | CGFloat buttonWH = (viewW-2*marginLRTB-(countInRow-1)*marginB)/countInRow; 125 | NSInteger indexX = (center.x <= buttonWH+marginLRTB+marginB) ? 0 : (center.x-buttonWH-marginLRTB-marginB)/(buttonWH+marginB)+1; 126 | NSInteger indexY = (center.y <= buttonWH+marginLRTB+marginB) ? 0 : (center.y-buttonWH-marginLRTB-marginB)/(buttonWH+marginB)+1; 127 | NSInteger buttonIndex = indexX + indexY*countInRow; 128 | NSInteger count = self.allButtons.count; 129 | //达到最大值和没有达到最大值情况不同 130 | if (!hasAddButton){ 131 | //达到最大值(没有添加按钮) 132 | if (buttonIndex >= count-1) { 133 | buttonIndex = count-1; 134 | } 135 | [self.allButtons removeObject:button]; 136 | [self.allButtons insertObject:button atIndex:buttonIndex]; 137 | [self layoutAllButtonsExcept:@[button] animated:NO]; 138 | }else{ 139 | //未达到最大值(有添加按钮) 140 | if (buttonIndex >= count-1) { 141 | buttonIndex = count-2; 142 | } 143 | [self.allButtons removeObject:button]; 144 | [self.allButtons insertObject:button atIndex:buttonIndex]; 145 | [self layoutAllButtonsExcept:@[button,self.allButtons.lastObject] animated:NO]; 146 | } 147 | 148 | } 149 | break; 150 | case UIGestureRecognizerStateEnded:{ 151 | [self layoutAllButtonsExcept:nil animated:YES]; 152 | //获取移动后的index 153 | NSInteger newIndex =[self.allButtons indexOfObject:button]; 154 | if ([self.dragViewDelegete respondsToSelector:@selector(imageDragViewDidMoveButtonFromIndex:toIndex:)] && newIndex != self.originIndex) { 155 | [self.dragViewDelegete imageDragViewDidMoveButtonFromIndex:self.originIndex toIndex:newIndex]; 156 | } 157 | } 158 | break; 159 | default: 160 | break; 161 | } 162 | } 163 | 164 | #pragma mark - layout 165 | - (void)layoutAllButtonsExcept:(NSArray *)buttons animated:(BOOL)animated{ 166 | //重新排列所有按钮 167 | NSInteger countInRow = self.kCountInRow; 168 | CGFloat marginLRTB = self.kMarginLRTB; 169 | CGFloat marginB = self.kMarginB; 170 | CGFloat viewW = self.frame.size.width; 171 | CGFloat buttonWH = (viewW-2*marginLRTB-(countInRow-1)*marginB)/countInRow; 172 | 173 | //手势处理时的动画(buttons有值的时候,忽略animated参数,默认有动画) 174 | if (buttons.count) { 175 | for (int i = 0; i=self.kMaxCount && self.allButtons.lastObject!=self.addButton) { 228 | return; 229 | } 230 | //添加一个照片按钮 231 | MQImageButton *button = [[MQImageButton alloc] initWithFrame:CGRectZero]; 232 | [button setImage:image forState:UIControlStateNormal]; 233 | [self addSubview:button]; 234 | [self.allButtons addObject:button]; 235 | 236 | //整理数组 237 | [self.allButtons removeObject:self.addButton]; 238 | if (self.allButtons.count < self.kMaxCount) { 239 | [self.allButtons addObject:self.addButton]; 240 | }else{ 241 | //满了,刚好把addButton挤掉 242 | self.addButton.hidden = YES; 243 | } 244 | 245 | __weak typeof(self) weakSelf = self; 246 | __weak typeof(button) weakbutton = button; 247 | //删除事件 248 | button.deleteButtonClickedBlock = ^(){ 249 | //移除 250 | NSInteger index = [weakSelf.allButtons indexOfObject:weakbutton]; 251 | [weakSelf.allButtons removeObject:weakbutton]; 252 | [weakbutton removeFromSuperview]; 253 | //添加按钮之前满的时候被隐藏了 254 | weakSelf.addButton.hidden = NO; 255 | if (![weakSelf.allButtons.lastObject isAddButton]) { 256 | [weakSelf.allButtons addObject:weakSelf.addButton]; 257 | } 258 | //布局 259 | [weakSelf layoutAllButtonsExcept:nil animated:YES]; 260 | //回调 261 | if ([weakSelf.dragViewDelegete respondsToSelector:@selector(imageDragViewDeleteButtonClickedAtIndex:)]) { 262 | [weakSelf.dragViewDelegete imageDragViewDeleteButtonClickedAtIndex:index]; 263 | } 264 | }; 265 | //点击事件 266 | button.buttonClickedBlock = ^(){ 267 | //回调 268 | NSInteger index = [weakSelf.allButtons indexOfObject:weakbutton]; 269 | if ([weakSelf.dragViewDelegete respondsToSelector:@selector(imageDragViewButtonClickedAtIndex:)]) { 270 | [weakSelf.dragViewDelegete imageDragViewButtonClickedAtIndex:index]; 271 | } 272 | }; 273 | 274 | //滑动手势 275 | UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognized:)]; 276 | longPress.minimumPressDuration = 0.15; 277 | longPress.delegate = self; 278 | [button addGestureRecognizer:longPress]; 279 | 280 | //布局 281 | [self layoutAllButtonsExcept:nil animated:NO]; 282 | } 283 | 284 | - (NSArray *)getAllImages{ 285 | NSMutableArray *images = [NSMutableArray array]; 286 | for (int i = 0; i 10 | #import "MQImageDragView.h" 11 | 12 | @interface TestTableViewCell : UITableViewCell 13 | @property (nonatomic,strong) MQImageDragView *dragView; 14 | @end 15 | -------------------------------------------------------------------------------- /MQImageDragView/TestTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // TestTableViewCell.m 3 | // MQImageDragView 4 | // 5 | // Created by ma on 16/1/25. 6 | // Copyright © 2016年 silvrunrun. All rights reserved. 7 | // 8 | 9 | #import "TestTableViewCell.h" 10 | #import "MQImageDragView.h" 11 | 12 | @interface TestTableViewCell () 13 | @end 14 | 15 | @implementation TestTableViewCell 16 | 17 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ 18 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 19 | if (self) { 20 | self.dragView = [[MQImageDragView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 0)]; 21 | self.dragView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.06]; 22 | self.dragView.kMarginLRTB = 5; 23 | self.dragView.kMarginB = 5; 24 | self.dragView.kMaxCount = 9; 25 | self.dragView.kCountInRow = 3; 26 | [self.contentView addSubview:self.dragView]; 27 | } 28 | return self; 29 | } 30 | 31 | - (void)layoutSubviews{ 32 | self.dragView.frame = self.bounds; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /MQImageDragView/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // MQImageDragView 4 | // 5 | // Created by ma on 16/1/25. 6 | // Copyright © 2016年 silvrunrun. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /MQImageDragView/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // MQImageDragView 4 | // 5 | // Created by ma on 16/1/25. 6 | // Copyright © 2016年 silvrunrun. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "MQImageDragView.h" 11 | #import "TestTableViewCell.h" 12 | 13 | @interface ViewController () 14 | @property (nonatomic,strong) UITableView *tableView; 15 | @property (nonatomic,strong) TestTableViewCell *cell; 16 | @end 17 | 18 | @implementation ViewController 19 | #pragma mark - view 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | self.view.backgroundColor = [UIColor whiteColor]; 23 | 24 | self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-20) style:UITableViewStylePlain]; 25 | self.tableView.delegate = self; 26 | self.tableView.dataSource = self; 27 | self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 28 | [self.view addSubview:self.tableView]; 29 | [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"]; 30 | self.cell = [[TestTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TestTableViewCell"]; 31 | self.cell.dragView.dragViewDelegete = self; 32 | 33 | [self imageDragViewAddButtonClicked]; 34 | [self imageDragViewAddButtonClicked]; 35 | [self imageDragViewAddButtonClicked]; 36 | [self imageDragViewAddButtonClicked]; 37 | } 38 | 39 | #pragma mark - table 40 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 41 | return 3; 42 | } 43 | 44 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 45 | if (indexPath.row == 0) { 46 | return self.cell; 47 | }else{ 48 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath]; 49 | cell.textLabel.textColor = [UIColor darkGrayColor]; 50 | if (indexPath.row == 1) { 51 | cell.textLabel.text = @"获取高度"; 52 | }else{ 53 | cell.textLabel.text = @"获取照片"; 54 | } 55 | return cell; 56 | } 57 | } 58 | 59 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 60 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 61 | if (indexPath.row == 1) { 62 | CGFloat height = [self.cell.dragView getHeightThatFit]; 63 | NSString *message = [NSString stringWithFormat:@"%.1f",height]; 64 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"高度" message:message delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 65 | [alert show]; 66 | }else if (indexPath.row == 2){ 67 | NSArray *images = [self.cell.dragView getAllImages]; 68 | NSString *message = [NSString stringWithFormat:@"%@",images]; 69 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"照片" message:message delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 70 | [alert show]; 71 | } 72 | } 73 | 74 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 75 | if (indexPath.row == 0) { 76 | return [self.cell.dragView getHeightThatFit]; 77 | }else{ 78 | return 45; 79 | } 80 | } 81 | 82 | #pragma mark - delegate 83 | - (void)imageDragViewAddButtonClicked{ 84 | NSLog(@"imageDragView---点击了添加按钮"); 85 | int randomNum = arc4random()%3+1; 86 | [self.cell.dragView addImage:[UIImage imageNamed:[NSString stringWithFormat:@"buttton_image%d",randomNum]]]; 87 | 88 | //刷新frame 89 | [self.tableView reloadData]; 90 | } 91 | 92 | - (void)imageDragViewDeleteButtonClickedAtIndex:(NSInteger)index{ 93 | NSLog(@"imageDragView---删除了%ld",index); 94 | 95 | //刷新frame 96 | [self.tableView reloadData]; 97 | } 98 | 99 | - (void)imageDragViewButtonClickedAtIndex:(NSInteger)index{ 100 | NSLog(@"imageDragView---点击了%ld",index); 101 | } 102 | 103 | - (void)imageDragViewDidMoveButtonFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex{ 104 | NSLog(@"imageDragView---移动:从%ld至%ld",fromIndex,toIndex); 105 | } 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /MQImageDragView/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // MQImageDragView 4 | // 5 | // Created by ma on 16/5/6. 6 | // Copyright © 2016年 silvrunrun. 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MQImageDragView 2 | 3 | 4 | ## 概述 5 | 6 | **iOS端仿微博的图片选择器,在发布新微博或者新状态时从相册选择完照片的照片容器,支持删除及拖动排序。** 7 | 8 | 9 | ![screenShot1](http://chuantu.biz/t4/8/1462498826x3738746523.jpg) 10 | ![screenShot2](http://chuantu.biz/t4/8/1462498900x3738746523.jpg) 11 | 12 | 13 | ## 用法 14 | 15 | ####1.初始化 16 | 17 | ``` 18 | //初始化时请设定宽度,高度不需设定(内部计算) 19 | MQImageDragView *dragView = [[MQImageDragView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 0)]; 20 | //上下左右的间距 21 | dragView.kMarginLRTB = 5; 22 | //图片之间的间距 23 | dragView.kMarginB = 5; 24 | //最大图片数量 25 | dragView.kMaxCount = 9; 26 | //每行的图片数量 27 | dragView.kCountInRow = 3; 28 | [self.view addSubview:self.dragView]; 29 | ``` 30 | 31 | ####2.公开方法 32 | 33 | ``` 34 | //添加一张照片 35 | - (void)addImage:(UIImage *)image; 36 | //获取所有照片 37 | - (NSArray *)getAllImages; 38 | //获取所有装图片的按钮 39 | - (NSArray *)getAllImageButtons; 40 | //获取本视图适当的高度(放入tableView中时,计算cell高度用) 41 | - (CGFloat)getHeightThatFit; 42 | ``` 43 | 44 | ####3.代理方法 45 | 46 | ``` 47 | //点击了添加按钮 48 | - (void)imageDragViewAddButtonClicked; 49 | //点击了删除按钮 50 | - (void)imageDragViewDeleteButtonClickedAtIndex:(NSInteger)index; 51 | //点击了某张图片 52 | - (void)imageDragViewButtonClickedAtIndex:(NSInteger)index; 53 | //移动了图片 54 | - (void)imageDragViewDidMoveButtonFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex; 55 | ``` 56 | --------------------------------------------------------------------------------