├── .gitignore ├── LICENSE ├── README.md ├── ZYDraggableView ├── UIView+ZYDraggable.h └── UIView+ZYDraggable.m ├── ZYDraggableViewDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── ZZY.xcuserdatad │ └── xcschemes │ ├── ZYDraggableViewDemo.xcscheme │ └── xcschememanagement.plist ├── ZYDraggableViewDemo ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── avatar.imageset │ │ ├── Contents.json │ │ └── avatar@2x.png │ └── background.imageset │ │ ├── Contents.json │ │ └── background@2x.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m └── preview.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | */build/* 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | *.hmap 18 | *.xccheckout 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 zy_zhang 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 | # ZYDraggableView 2 | - An UIView category which make view draggable. Inspired by [即刻](https://itunes.apple.com/cn/app/ji-ke-yong-zui-lan-fang-shi/id966129812?mt=8) and [一元进宝](https://itunes.apple.com/cn/app/yi-yuan-jin-bao-quan-min-yi/id1056900729?mt=8). 3 | 4 | ![](./preview.gif) 5 | 6 | ## Feature 7 | 8 | - [x] Make view become draggable which inherited from UIView. 9 | - [x] Integrate draggable view **just one line of code**. 10 | 11 | ## Usage 12 | 13 | ```Objective-C 14 | [view makeDraggable]; 15 | ``` 16 | 17 | ## Requirements 18 | 19 | - iOS 7.0+ 20 | - Xcode 5.0+ 21 | 22 | ## Installation 23 | 24 | Add manually: 25 | - Drag `ZYDraggableView` folder to your project. 26 | - Import header file: `#import "ZYDraggableView.h"` 27 | 28 | ## FAQ 29 | 30 | 1. Sometimes draggable view was blocked by other views. 31 | 32 | > This is depend on draggable view's hierarchical on superview. You can call `-bringSubviewToFront:` to make draggable view above sibling views. 33 | 34 | ## License 35 | 36 | ZYDraggableView is released under the MIT license. See LICENSE for details. 37 | -------------------------------------------------------------------------------- /ZYDraggableView/UIView+ZYDraggable.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+ZYDraggable.h 3 | // DraggableView 4 | // 5 | // Created by 张志延 on 16/8/25. (https://github.com/zzyspace) 6 | // Copyright © 2016年 tongbu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (Draggable) 12 | 13 | /** 14 | * Make view draggable. 15 | * 16 | * @param view Animator reference view, usually is super view. 17 | * @param damping Value from 0.0 to 1.0. 0.0 is the least oscillation. default is 0.4. 18 | */ 19 | - (void)makeDraggableInView:(UIView *)view damping:(CGFloat)damping; 20 | - (void)makeDraggable; 21 | 22 | /** 23 | * Disable view draggable. 24 | */ 25 | - (void)removeDraggable; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /ZYDraggableView/UIView+ZYDraggable.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+ZYDraggable.m 3 | // DraggableView 4 | // 5 | // Created by 张志延 on 16/8/25. (https://github.com/zzyspace) 6 | // Copyright © 2016年 tongbu. All rights reserved. 7 | // 8 | 9 | #import "UIView+ZYDraggable.h" 10 | #import 11 | 12 | @implementation UIView (Draggable) 13 | 14 | - (void)makeDraggable 15 | { 16 | NSAssert(self.superview, @"Super view is required when make view draggable"); 17 | 18 | [self makeDraggableInView:self.superview damping:0.4]; 19 | } 20 | 21 | - (void)makeDraggableInView:(UIView *)view damping:(CGFloat)damping 22 | { 23 | if (!view) return; 24 | [self removeDraggable]; 25 | 26 | self.zy_playground = view; 27 | self.zy_damping = damping; 28 | 29 | [self zy_creatAnimator]; 30 | [self zy_addPanGesture]; 31 | } 32 | 33 | - (void)removeDraggable 34 | { 35 | [self removeGestureRecognizer:self.zy_panGesture]; 36 | self.zy_panGesture = nil; 37 | self.zy_playground = nil; 38 | self.zy_animator = nil; 39 | self.zy_snapBehavior = nil; 40 | self.zy_attachmentBehavior = nil; 41 | self.zy_centerPoint = CGPointZero; 42 | } 43 | 44 | - (void)updateSnapPoint 45 | { 46 | self.zy_centerPoint = [self convertPoint:CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2) toView:self.zy_playground]; 47 | self.zy_snapBehavior = [[UISnapBehavior alloc] initWithItem:self snapToPoint:self.zy_centerPoint]; 48 | self.zy_snapBehavior.damping = self.zy_damping; 49 | } 50 | 51 | - (void)zy_creatAnimator 52 | { 53 | self.zy_animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.zy_playground]; 54 | [self updateSnapPoint]; 55 | } 56 | 57 | - (void)zy_addPanGesture 58 | { 59 | self.zy_panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(zy_panGesture:)]; 60 | [self addGestureRecognizer:self.zy_panGesture]; 61 | } 62 | 63 | #pragma mark - Gesture 64 | 65 | - (void)zy_panGesture:(UIPanGestureRecognizer *)pan 66 | { 67 | CGPoint panLocation = [pan locationInView:self.zy_playground]; 68 | 69 | if (pan.state == UIGestureRecognizerStateBegan) 70 | { 71 | [self updateSnapPoint]; 72 | 73 | UIOffset offset = UIOffsetMake(panLocation.x - self.zy_centerPoint.x, panLocation.y - self.zy_centerPoint.y); 74 | [self.zy_animator removeAllBehaviors]; 75 | self.zy_attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self 76 | offsetFromCenter:offset 77 | attachedToAnchor:panLocation]; 78 | [self.zy_animator addBehavior:self.zy_attachmentBehavior]; 79 | } 80 | else if (pan.state == UIGestureRecognizerStateChanged) 81 | { 82 | [self.zy_attachmentBehavior setAnchorPoint:panLocation]; 83 | } 84 | else if (pan.state == UIGestureRecognizerStateEnded || 85 | pan.state == UIGestureRecognizerStateCancelled || 86 | pan.state == UIGestureRecognizerStateFailed) 87 | { 88 | [self.zy_animator addBehavior:self.zy_snapBehavior]; 89 | [self.zy_animator removeBehavior:self.zy_attachmentBehavior]; 90 | } 91 | } 92 | 93 | #pragma mark - Associated Object 94 | 95 | - (void)setZy_playground:(id)object { 96 | objc_setAssociatedObject(self, @selector(zy_playground), object, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 97 | } 98 | - (UIView *)zy_playground { 99 | return objc_getAssociatedObject(self, @selector(zy_playground)); 100 | } 101 | 102 | - (void)setZy_animator:(id)object { 103 | objc_setAssociatedObject(self, @selector(zy_animator), object, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 104 | } 105 | - (UIDynamicAnimator *)zy_animator { 106 | return objc_getAssociatedObject(self, @selector(zy_animator)); 107 | } 108 | 109 | - (void)setZy_snapBehavior:(id)object { 110 | objc_setAssociatedObject(self, @selector(zy_snapBehavior), object, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 111 | } 112 | - (UISnapBehavior *)zy_snapBehavior { 113 | return objc_getAssociatedObject(self, @selector(zy_snapBehavior)); 114 | } 115 | 116 | - (void)setZy_attachmentBehavior:(id)object { 117 | objc_setAssociatedObject(self, @selector(zy_attachmentBehavior), object, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 118 | } 119 | - (UIAttachmentBehavior *)zy_attachmentBehavior { 120 | return objc_getAssociatedObject(self, @selector(zy_attachmentBehavior)); 121 | } 122 | 123 | - (void)setZy_panGesture:(id)object { 124 | objc_setAssociatedObject(self, @selector(zy_panGesture), object, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 125 | } 126 | - (UIPanGestureRecognizer *)zy_panGesture { 127 | return objc_getAssociatedObject(self, @selector(zy_panGesture)); 128 | } 129 | 130 | - (void)setZy_centerPoint:(CGPoint)point { 131 | objc_setAssociatedObject(self, @selector(zy_centerPoint), [NSValue valueWithCGPoint:point], OBJC_ASSOCIATION_RETAIN_NONATOMIC); 132 | } 133 | - (CGPoint)zy_centerPoint { 134 | return [objc_getAssociatedObject(self, @selector(zy_centerPoint)) CGPointValue]; 135 | } 136 | 137 | - (void)setZy_damping:(CGFloat)damping { 138 | objc_setAssociatedObject(self, @selector(zy_damping), @(damping), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 139 | } 140 | - (CGFloat)zy_damping { 141 | return [objc_getAssociatedObject(self, @selector(zy_damping)) floatValue]; 142 | } 143 | 144 | @end 145 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5A6022631D7028500026451A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A6022621D7028500026451A /* main.m */; }; 11 | 5A6022661D7028500026451A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A6022651D7028500026451A /* AppDelegate.m */; }; 12 | 5A6022691D7028500026451A /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A6022681D7028500026451A /* ViewController.m */; }; 13 | 5A60226C1D7028500026451A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5A60226A1D7028500026451A /* Main.storyboard */; }; 14 | 5A60226E1D7028500026451A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5A60226D1D7028500026451A /* Assets.xcassets */; }; 15 | 5A6022711D7028500026451A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5A60226F1D7028500026451A /* LaunchScreen.storyboard */; }; 16 | 5A60227B1D70290B0026451A /* UIView+ZYDraggable.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A60227A1D70290B0026451A /* UIView+ZYDraggable.m */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 5A60225E1D7028500026451A /* ZYDraggableViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ZYDraggableViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 5A6022621D7028500026451A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 22 | 5A6022641D7028500026451A /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 23 | 5A6022651D7028500026451A /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 24 | 5A6022671D7028500026451A /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 25 | 5A6022681D7028500026451A /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 26 | 5A60226B1D7028500026451A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 27 | 5A60226D1D7028500026451A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 28 | 5A6022701D7028500026451A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | 5A6022721D7028500026451A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 5A6022791D70290B0026451A /* UIView+ZYDraggable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+ZYDraggable.h"; sourceTree = ""; }; 31 | 5A60227A1D70290B0026451A /* UIView+ZYDraggable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+ZYDraggable.m"; sourceTree = ""; }; 32 | /* End PBXFileReference section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | 5A60225B1D7028500026451A /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | ); 40 | runOnlyForDeploymentPostprocessing = 0; 41 | }; 42 | /* End PBXFrameworksBuildPhase section */ 43 | 44 | /* Begin PBXGroup section */ 45 | 5A6022551D7028500026451A = { 46 | isa = PBXGroup; 47 | children = ( 48 | 5A6022601D7028500026451A /* ZYDraggableViewDemo */, 49 | 5A60225F1D7028500026451A /* Products */, 50 | ); 51 | sourceTree = ""; 52 | }; 53 | 5A60225F1D7028500026451A /* Products */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | 5A60225E1D7028500026451A /* ZYDraggableViewDemo.app */, 57 | ); 58 | name = Products; 59 | sourceTree = ""; 60 | }; 61 | 5A6022601D7028500026451A /* ZYDraggableViewDemo */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | 5A6022781D70290B0026451A /* ZYDraggableView */, 65 | 5A6022641D7028500026451A /* AppDelegate.h */, 66 | 5A6022651D7028500026451A /* AppDelegate.m */, 67 | 5A6022671D7028500026451A /* ViewController.h */, 68 | 5A6022681D7028500026451A /* ViewController.m */, 69 | 5A60226A1D7028500026451A /* Main.storyboard */, 70 | 5A60226D1D7028500026451A /* Assets.xcassets */, 71 | 5A60226F1D7028500026451A /* LaunchScreen.storyboard */, 72 | 5A6022721D7028500026451A /* Info.plist */, 73 | 5A6022611D7028500026451A /* Supporting Files */, 74 | ); 75 | path = ZYDraggableViewDemo; 76 | sourceTree = ""; 77 | }; 78 | 5A6022611D7028500026451A /* Supporting Files */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 5A6022621D7028500026451A /* main.m */, 82 | ); 83 | name = "Supporting Files"; 84 | sourceTree = ""; 85 | }; 86 | 5A6022781D70290B0026451A /* ZYDraggableView */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 5A6022791D70290B0026451A /* UIView+ZYDraggable.h */, 90 | 5A60227A1D70290B0026451A /* UIView+ZYDraggable.m */, 91 | ); 92 | path = ZYDraggableView; 93 | sourceTree = SOURCE_ROOT; 94 | }; 95 | /* End PBXGroup section */ 96 | 97 | /* Begin PBXNativeTarget section */ 98 | 5A60225D1D7028500026451A /* ZYDraggableViewDemo */ = { 99 | isa = PBXNativeTarget; 100 | buildConfigurationList = 5A6022751D7028500026451A /* Build configuration list for PBXNativeTarget "ZYDraggableViewDemo" */; 101 | buildPhases = ( 102 | 5A60225A1D7028500026451A /* Sources */, 103 | 5A60225B1D7028500026451A /* Frameworks */, 104 | 5A60225C1D7028500026451A /* Resources */, 105 | ); 106 | buildRules = ( 107 | ); 108 | dependencies = ( 109 | ); 110 | name = ZYDraggableViewDemo; 111 | productName = ZYDraggableViewDemo; 112 | productReference = 5A60225E1D7028500026451A /* ZYDraggableViewDemo.app */; 113 | productType = "com.apple.product-type.application"; 114 | }; 115 | /* End PBXNativeTarget section */ 116 | 117 | /* Begin PBXProject section */ 118 | 5A6022561D7028500026451A /* Project object */ = { 119 | isa = PBXProject; 120 | attributes = { 121 | LastUpgradeCheck = 0730; 122 | ORGANIZATIONNAME = tongbu; 123 | TargetAttributes = { 124 | 5A60225D1D7028500026451A = { 125 | CreatedOnToolsVersion = 7.3.1; 126 | }; 127 | }; 128 | }; 129 | buildConfigurationList = 5A6022591D7028500026451A /* Build configuration list for PBXProject "ZYDraggableViewDemo" */; 130 | compatibilityVersion = "Xcode 3.2"; 131 | developmentRegion = English; 132 | hasScannedForEncodings = 0; 133 | knownRegions = ( 134 | en, 135 | Base, 136 | ); 137 | mainGroup = 5A6022551D7028500026451A; 138 | productRefGroup = 5A60225F1D7028500026451A /* Products */; 139 | projectDirPath = ""; 140 | projectRoot = ""; 141 | targets = ( 142 | 5A60225D1D7028500026451A /* ZYDraggableViewDemo */, 143 | ); 144 | }; 145 | /* End PBXProject section */ 146 | 147 | /* Begin PBXResourcesBuildPhase section */ 148 | 5A60225C1D7028500026451A /* Resources */ = { 149 | isa = PBXResourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | 5A6022711D7028500026451A /* LaunchScreen.storyboard in Resources */, 153 | 5A60226E1D7028500026451A /* Assets.xcassets in Resources */, 154 | 5A60226C1D7028500026451A /* Main.storyboard in Resources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXResourcesBuildPhase section */ 159 | 160 | /* Begin PBXSourcesBuildPhase section */ 161 | 5A60225A1D7028500026451A /* Sources */ = { 162 | isa = PBXSourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | 5A6022691D7028500026451A /* ViewController.m in Sources */, 166 | 5A6022661D7028500026451A /* AppDelegate.m in Sources */, 167 | 5A6022631D7028500026451A /* main.m in Sources */, 168 | 5A60227B1D70290B0026451A /* UIView+ZYDraggable.m in Sources */, 169 | ); 170 | runOnlyForDeploymentPostprocessing = 0; 171 | }; 172 | /* End PBXSourcesBuildPhase section */ 173 | 174 | /* Begin PBXVariantGroup section */ 175 | 5A60226A1D7028500026451A /* Main.storyboard */ = { 176 | isa = PBXVariantGroup; 177 | children = ( 178 | 5A60226B1D7028500026451A /* Base */, 179 | ); 180 | name = Main.storyboard; 181 | sourceTree = ""; 182 | }; 183 | 5A60226F1D7028500026451A /* LaunchScreen.storyboard */ = { 184 | isa = PBXVariantGroup; 185 | children = ( 186 | 5A6022701D7028500026451A /* Base */, 187 | ); 188 | name = LaunchScreen.storyboard; 189 | sourceTree = ""; 190 | }; 191 | /* End PBXVariantGroup section */ 192 | 193 | /* Begin XCBuildConfiguration section */ 194 | 5A6022731D7028500026451A /* Debug */ = { 195 | isa = XCBuildConfiguration; 196 | buildSettings = { 197 | ALWAYS_SEARCH_USER_PATHS = NO; 198 | CLANG_ANALYZER_NONNULL = YES; 199 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 200 | CLANG_CXX_LIBRARY = "libc++"; 201 | CLANG_ENABLE_MODULES = YES; 202 | CLANG_ENABLE_OBJC_ARC = YES; 203 | CLANG_WARN_BOOL_CONVERSION = YES; 204 | CLANG_WARN_CONSTANT_CONVERSION = YES; 205 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 206 | CLANG_WARN_EMPTY_BODY = YES; 207 | CLANG_WARN_ENUM_CONVERSION = YES; 208 | CLANG_WARN_INT_CONVERSION = YES; 209 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 210 | CLANG_WARN_UNREACHABLE_CODE = YES; 211 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 212 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 213 | COPY_PHASE_STRIP = NO; 214 | DEBUG_INFORMATION_FORMAT = dwarf; 215 | ENABLE_STRICT_OBJC_MSGSEND = YES; 216 | ENABLE_TESTABILITY = YES; 217 | GCC_C_LANGUAGE_STANDARD = gnu99; 218 | GCC_DYNAMIC_NO_PIC = NO; 219 | GCC_NO_COMMON_BLOCKS = YES; 220 | GCC_OPTIMIZATION_LEVEL = 0; 221 | GCC_PREPROCESSOR_DEFINITIONS = ( 222 | "DEBUG=1", 223 | "$(inherited)", 224 | ); 225 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 226 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 227 | GCC_WARN_UNDECLARED_SELECTOR = YES; 228 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 229 | GCC_WARN_UNUSED_FUNCTION = YES; 230 | GCC_WARN_UNUSED_VARIABLE = YES; 231 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 232 | MTL_ENABLE_DEBUG_INFO = YES; 233 | ONLY_ACTIVE_ARCH = YES; 234 | SDKROOT = iphoneos; 235 | TARGETED_DEVICE_FAMILY = "1,2"; 236 | }; 237 | name = Debug; 238 | }; 239 | 5A6022741D7028500026451A /* Release */ = { 240 | isa = XCBuildConfiguration; 241 | buildSettings = { 242 | ALWAYS_SEARCH_USER_PATHS = NO; 243 | CLANG_ANALYZER_NONNULL = YES; 244 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 245 | CLANG_CXX_LIBRARY = "libc++"; 246 | CLANG_ENABLE_MODULES = YES; 247 | CLANG_ENABLE_OBJC_ARC = YES; 248 | CLANG_WARN_BOOL_CONVERSION = YES; 249 | CLANG_WARN_CONSTANT_CONVERSION = YES; 250 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 251 | CLANG_WARN_EMPTY_BODY = YES; 252 | CLANG_WARN_ENUM_CONVERSION = YES; 253 | CLANG_WARN_INT_CONVERSION = YES; 254 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 255 | CLANG_WARN_UNREACHABLE_CODE = YES; 256 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 257 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 258 | COPY_PHASE_STRIP = NO; 259 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 260 | ENABLE_NS_ASSERTIONS = NO; 261 | ENABLE_STRICT_OBJC_MSGSEND = YES; 262 | GCC_C_LANGUAGE_STANDARD = gnu99; 263 | GCC_NO_COMMON_BLOCKS = YES; 264 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 265 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 266 | GCC_WARN_UNDECLARED_SELECTOR = YES; 267 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 268 | GCC_WARN_UNUSED_FUNCTION = YES; 269 | GCC_WARN_UNUSED_VARIABLE = YES; 270 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 271 | MTL_ENABLE_DEBUG_INFO = NO; 272 | SDKROOT = iphoneos; 273 | TARGETED_DEVICE_FAMILY = "1,2"; 274 | VALIDATE_PRODUCT = YES; 275 | }; 276 | name = Release; 277 | }; 278 | 5A6022761D7028500026451A /* Debug */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 282 | CODE_SIGN_IDENTITY = "iPhone Developer"; 283 | INFOPLIST_FILE = ZYDraggableViewDemo/Info.plist; 284 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 285 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 286 | PRODUCT_BUNDLE_IDENTIFIER = com.zzy.ZYDraggableViewDemo; 287 | PRODUCT_NAME = "$(TARGET_NAME)"; 288 | }; 289 | name = Debug; 290 | }; 291 | 5A6022771D7028500026451A /* Release */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 295 | CODE_SIGN_IDENTITY = "iPhone Developer"; 296 | INFOPLIST_FILE = ZYDraggableViewDemo/Info.plist; 297 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 298 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 299 | PRODUCT_BUNDLE_IDENTIFIER = com.zzy.ZYDraggableViewDemo; 300 | PRODUCT_NAME = "$(TARGET_NAME)"; 301 | }; 302 | name = Release; 303 | }; 304 | /* End XCBuildConfiguration section */ 305 | 306 | /* Begin XCConfigurationList section */ 307 | 5A6022591D7028500026451A /* Build configuration list for PBXProject "ZYDraggableViewDemo" */ = { 308 | isa = XCConfigurationList; 309 | buildConfigurations = ( 310 | 5A6022731D7028500026451A /* Debug */, 311 | 5A6022741D7028500026451A /* Release */, 312 | ); 313 | defaultConfigurationIsVisible = 0; 314 | defaultConfigurationName = Release; 315 | }; 316 | 5A6022751D7028500026451A /* Build configuration list for PBXNativeTarget "ZYDraggableViewDemo" */ = { 317 | isa = XCConfigurationList; 318 | buildConfigurations = ( 319 | 5A6022761D7028500026451A /* Debug */, 320 | 5A6022771D7028500026451A /* Release */, 321 | ); 322 | defaultConfigurationIsVisible = 0; 323 | defaultConfigurationName = Release; 324 | }; 325 | /* End XCConfigurationList section */ 326 | }; 327 | rootObject = 5A6022561D7028500026451A /* Project object */; 328 | } 329 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo.xcodeproj/xcuserdata/ZZY.xcuserdatad/xcschemes/ZYDraggableViewDemo.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 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo.xcodeproj/xcuserdata/ZZY.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ZYDraggableViewDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 5A60225D1D7028500026451A 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ZYDraggableViewDemo 4 | // 5 | // Created by 张志延 on 16/8/26. 6 | // Copyright © 2016年 tongbu. 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 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ZYDraggableViewDemo 4 | // 5 | // Created by 张志延 on 16/8/26. 6 | // Copyright © 2016年 tongbu. 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 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo/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 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /ZYDraggableViewDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ZYDraggableViewDemo/Assets.xcassets/avatar.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "avatar@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 | } -------------------------------------------------------------------------------- /ZYDraggableViewDemo/Assets.xcassets/avatar.imageset/avatar@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzyspace/ZYDraggableView/c40f57d852f454bf9dde64578aad26435ea5b174/ZYDraggableViewDemo/Assets.xcassets/avatar.imageset/avatar@2x.png -------------------------------------------------------------------------------- /ZYDraggableViewDemo/Assets.xcassets/background.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "background@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 | } -------------------------------------------------------------------------------- /ZYDraggableViewDemo/Assets.xcassets/background.imageset/background@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzyspace/ZYDraggableView/c40f57d852f454bf9dde64578aad26435ea5b174/ZYDraggableViewDemo/Assets.xcassets/background.imageset/background@2x.png -------------------------------------------------------------------------------- /ZYDraggableViewDemo/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 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo/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 | UIStatusBarStyle 34 | UIStatusBarStyleLightContent 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ZYDraggableViewDemo 4 | // 5 | // Created by 张志延 on 16/8/26. 6 | // Copyright © 2016年 tongbu. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ZYDraggableViewDemo 4 | // 5 | // Created by 张志延 on 16/8/26. 6 | // Copyright © 2016年 tongbu. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "UIView+ZYDraggable.h" 11 | 12 | @interface ViewController () 13 | 14 | @property (weak, nonatomic) IBOutlet UIImageView *avatarView; 15 | 16 | @end 17 | 18 | @implementation ViewController 19 | 20 | - (void)viewDidLoad { 21 | [super viewDidLoad]; 22 | 23 | // UIImageView ignored user events by default, so set 24 | // `userInteractionEnabled` to YES for receive touch events. 25 | self.avatarView.userInteractionEnabled = YES; 26 | 27 | // Make avatarView draggable 28 | [self.avatarView makeDraggable]; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /ZYDraggableViewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ZYDraggableViewDemo 4 | // 5 | // Created by 张志延 on 16/8/26. 6 | // Copyright © 2016年 tongbu. 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 | -------------------------------------------------------------------------------- /preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zzyspace/ZYDraggableView/c40f57d852f454bf9dde64578aad26435ea5b174/preview.gif --------------------------------------------------------------------------------