├── README.md ├── TanTan.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── caibde.xcuserdatad │ └── xcschemes │ ├── TanTan.xcscheme │ └── xcschememanagement.plist ├── TanTan ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── TanTanView.h │ └── TanTanView.m ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m ├── TanTanTests ├── Info.plist └── TanTanTests.m └── TanTanUITests ├── Info.plist └── TanTanUITests.m /README.md: -------------------------------------------------------------------------------- 1 | # TanTan 2 | 探探 和 陌陌 都有 3 | # 前提 4 | 现在比较流行的社交软件都有这么一个功能模块,喜欢←划,不喜欢→划, 多么经典的一个广告语啊。 5 | 我就在业余时间写了这么一个demo样例 6 | ![WechatIMG1.jpeg](http://upload-images.jianshu.io/upload_images/2368708-4e36e014ffd22e6b.jpeg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 7 | ![WechatIMG2.jpeg](http://upload-images.jianshu.io/upload_images/2368708-75a6f0776d34d952.jpeg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 8 | 9 | 这两个都是比较参数经典的案例 10 | # 参数 11 | ```objc 12 | //代理 13 | @property (nonatomic, weak) iddelegate; 14 | //数据源 15 | @property (nonatomic, weak) iddataSource; 16 | //是否设置循环 17 | @property (nonatomic, assign) BOOL isCyclically; 18 | //展示出来的item数目 19 | @property (nonatomic, assign) NSInteger showItemsNumber; 20 | //设置偏移量 21 | @property (nonatomic, assign) CGSize offSet; 22 | //显示的第一个View 23 | @property (nonatomic, strong , readonly) UIView *topView; 24 | //刷新展示数据 25 | - (void)refreshData; 26 | ``` 27 | 我们可以通过设置isCyclically来实现视图是否循环,通过offset来设置重叠视图的重叠方向 ` 28 | ```objc 29 | @protocol TanTanDataSource 30 | @required 31 | - (NSInteger)numberOfItemInTanTan:(TanTanView *)tantan; 32 | 33 | - (UIView *)tantan:(TanTanView *)tantan 34 | viewForItemAtIndex:(NSInteger)index 35 | reusingView:(UIView *)view; 36 | @end 37 | ``` 38 | 上面的这个是数据源,这两个方法的思路和UITableView的数据源差不多,一个是设置数据源数目,一个就是视图复用 39 | ```objc 40 | @protocol TanTanDelegate 41 | @optional 42 | - (void)tantan:(TanTanView *)tantan beforeSwipingItemAtIndex:(NSInteger)index; 43 | - (void)tantan:(TanTanView *)tantan didRemovedItemAtIndex:(NSInteger)index; 44 | - (void)tantan:(TanTanView *)tantan didLeftRemovedItemAtIndex:(NSInteger)index; 45 | - (void)tantan:(TanTanView *)tantan didRightRemovedItemAtIndex:(NSInteger)index; 46 | ``` 47 | 这就是相应的代理方法 48 | # GIF演示 49 | ![探探.gif](http://upload-images.jianshu.io/upload_images/2368708-878318fdb11db7c5.gif?imageMogr2/auto-orient/strip) 50 | # 更新 51 | 当页面快速滑动的时候视图会出现BUG,已修复 52 | -------------------------------------------------------------------------------- /TanTan.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 9AB8F4F71E5A903200C7A98F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AB8F4F61E5A903200C7A98F /* main.m */; }; 11 | 9AB8F4FA1E5A903200C7A98F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AB8F4F91E5A903200C7A98F /* AppDelegate.m */; }; 12 | 9AB8F4FD1E5A903200C7A98F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AB8F4FC1E5A903200C7A98F /* ViewController.m */; }; 13 | 9AB8F5001E5A903200C7A98F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9AB8F4FE1E5A903200C7A98F /* Main.storyboard */; }; 14 | 9AB8F5021E5A903200C7A98F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9AB8F5011E5A903200C7A98F /* Assets.xcassets */; }; 15 | 9AB8F5051E5A903200C7A98F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9AB8F5031E5A903200C7A98F /* LaunchScreen.storyboard */; }; 16 | 9AB8F5101E5A903200C7A98F /* TanTanTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AB8F50F1E5A903200C7A98F /* TanTanTests.m */; }; 17 | 9AB8F51B1E5A903200C7A98F /* TanTanUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AB8F51A1E5A903200C7A98F /* TanTanUITests.m */; }; 18 | 9AB8F52A1E5A90A500C7A98F /* TanTanView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AB8F5291E5A90A500C7A98F /* TanTanView.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 9AB8F50C1E5A903200C7A98F /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 9AB8F4EA1E5A903100C7A98F /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 9AB8F4F11E5A903100C7A98F; 27 | remoteInfo = TanTan; 28 | }; 29 | 9AB8F5171E5A903200C7A98F /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = 9AB8F4EA1E5A903100C7A98F /* Project object */; 32 | proxyType = 1; 33 | remoteGlobalIDString = 9AB8F4F11E5A903100C7A98F; 34 | remoteInfo = TanTan; 35 | }; 36 | /* End PBXContainerItemProxy section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | 9AB8F4F21E5A903100C7A98F /* TanTan.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TanTan.app; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | 9AB8F4F61E5A903200C7A98F /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 41 | 9AB8F4F81E5A903200C7A98F /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 42 | 9AB8F4F91E5A903200C7A98F /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 43 | 9AB8F4FB1E5A903200C7A98F /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 44 | 9AB8F4FC1E5A903200C7A98F /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 45 | 9AB8F4FF1E5A903200C7A98F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 46 | 9AB8F5011E5A903200C7A98F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 47 | 9AB8F5041E5A903200C7A98F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 48 | 9AB8F5061E5A903200C7A98F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 49 | 9AB8F50B1E5A903200C7A98F /* TanTanTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TanTanTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 9AB8F50F1E5A903200C7A98F /* TanTanTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TanTanTests.m; sourceTree = ""; }; 51 | 9AB8F5111E5A903200C7A98F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | 9AB8F5161E5A903200C7A98F /* TanTanUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TanTanUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 9AB8F51A1E5A903200C7A98F /* TanTanUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TanTanUITests.m; sourceTree = ""; }; 54 | 9AB8F51C1E5A903200C7A98F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 55 | 9AB8F5281E5A90A500C7A98F /* TanTanView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TanTanView.h; path = Assets.xcassets/TanTanView.h; sourceTree = ""; }; 56 | 9AB8F5291E5A90A500C7A98F /* TanTanView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TanTanView.m; path = Assets.xcassets/TanTanView.m; sourceTree = ""; }; 57 | /* End PBXFileReference section */ 58 | 59 | /* Begin PBXFrameworksBuildPhase section */ 60 | 9AB8F4EF1E5A903100C7A98F /* Frameworks */ = { 61 | isa = PBXFrameworksBuildPhase; 62 | buildActionMask = 2147483647; 63 | files = ( 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | 9AB8F5081E5A903200C7A98F /* Frameworks */ = { 68 | isa = PBXFrameworksBuildPhase; 69 | buildActionMask = 2147483647; 70 | files = ( 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | 9AB8F5131E5A903200C7A98F /* Frameworks */ = { 75 | isa = PBXFrameworksBuildPhase; 76 | buildActionMask = 2147483647; 77 | files = ( 78 | ); 79 | runOnlyForDeploymentPostprocessing = 0; 80 | }; 81 | /* End PBXFrameworksBuildPhase section */ 82 | 83 | /* Begin PBXGroup section */ 84 | 9AB8F4E91E5A903100C7A98F = { 85 | isa = PBXGroup; 86 | children = ( 87 | 9AB8F4F41E5A903100C7A98F /* TanTan */, 88 | 9AB8F50E1E5A903200C7A98F /* TanTanTests */, 89 | 9AB8F5191E5A903200C7A98F /* TanTanUITests */, 90 | 9AB8F4F31E5A903100C7A98F /* Products */, 91 | ); 92 | sourceTree = ""; 93 | }; 94 | 9AB8F4F31E5A903100C7A98F /* Products */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 9AB8F4F21E5A903100C7A98F /* TanTan.app */, 98 | 9AB8F50B1E5A903200C7A98F /* TanTanTests.xctest */, 99 | 9AB8F5161E5A903200C7A98F /* TanTanUITests.xctest */, 100 | ); 101 | name = Products; 102 | sourceTree = ""; 103 | }; 104 | 9AB8F4F41E5A903100C7A98F /* TanTan */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 9AB8F4F81E5A903200C7A98F /* AppDelegate.h */, 108 | 9AB8F4F91E5A903200C7A98F /* AppDelegate.m */, 109 | 9AB8F4FB1E5A903200C7A98F /* ViewController.h */, 110 | 9AB8F4FC1E5A903200C7A98F /* ViewController.m */, 111 | 9AB8F5281E5A90A500C7A98F /* TanTanView.h */, 112 | 9AB8F5291E5A90A500C7A98F /* TanTanView.m */, 113 | 9AB8F4FE1E5A903200C7A98F /* Main.storyboard */, 114 | 9AB8F5011E5A903200C7A98F /* Assets.xcassets */, 115 | 9AB8F5031E5A903200C7A98F /* LaunchScreen.storyboard */, 116 | 9AB8F5061E5A903200C7A98F /* Info.plist */, 117 | 9AB8F4F51E5A903100C7A98F /* Supporting Files */, 118 | ); 119 | path = TanTan; 120 | sourceTree = ""; 121 | }; 122 | 9AB8F4F51E5A903100C7A98F /* Supporting Files */ = { 123 | isa = PBXGroup; 124 | children = ( 125 | 9AB8F4F61E5A903200C7A98F /* main.m */, 126 | ); 127 | name = "Supporting Files"; 128 | sourceTree = ""; 129 | }; 130 | 9AB8F50E1E5A903200C7A98F /* TanTanTests */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | 9AB8F50F1E5A903200C7A98F /* TanTanTests.m */, 134 | 9AB8F5111E5A903200C7A98F /* Info.plist */, 135 | ); 136 | path = TanTanTests; 137 | sourceTree = ""; 138 | }; 139 | 9AB8F5191E5A903200C7A98F /* TanTanUITests */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | 9AB8F51A1E5A903200C7A98F /* TanTanUITests.m */, 143 | 9AB8F51C1E5A903200C7A98F /* Info.plist */, 144 | ); 145 | path = TanTanUITests; 146 | sourceTree = ""; 147 | }; 148 | /* End PBXGroup section */ 149 | 150 | /* Begin PBXNativeTarget section */ 151 | 9AB8F4F11E5A903100C7A98F /* TanTan */ = { 152 | isa = PBXNativeTarget; 153 | buildConfigurationList = 9AB8F51F1E5A903200C7A98F /* Build configuration list for PBXNativeTarget "TanTan" */; 154 | buildPhases = ( 155 | 9AB8F4EE1E5A903100C7A98F /* Sources */, 156 | 9AB8F4EF1E5A903100C7A98F /* Frameworks */, 157 | 9AB8F4F01E5A903100C7A98F /* Resources */, 158 | ); 159 | buildRules = ( 160 | ); 161 | dependencies = ( 162 | ); 163 | name = TanTan; 164 | productName = TanTan; 165 | productReference = 9AB8F4F21E5A903100C7A98F /* TanTan.app */; 166 | productType = "com.apple.product-type.application"; 167 | }; 168 | 9AB8F50A1E5A903200C7A98F /* TanTanTests */ = { 169 | isa = PBXNativeTarget; 170 | buildConfigurationList = 9AB8F5221E5A903200C7A98F /* Build configuration list for PBXNativeTarget "TanTanTests" */; 171 | buildPhases = ( 172 | 9AB8F5071E5A903200C7A98F /* Sources */, 173 | 9AB8F5081E5A903200C7A98F /* Frameworks */, 174 | 9AB8F5091E5A903200C7A98F /* Resources */, 175 | ); 176 | buildRules = ( 177 | ); 178 | dependencies = ( 179 | 9AB8F50D1E5A903200C7A98F /* PBXTargetDependency */, 180 | ); 181 | name = TanTanTests; 182 | productName = TanTanTests; 183 | productReference = 9AB8F50B1E5A903200C7A98F /* TanTanTests.xctest */; 184 | productType = "com.apple.product-type.bundle.unit-test"; 185 | }; 186 | 9AB8F5151E5A903200C7A98F /* TanTanUITests */ = { 187 | isa = PBXNativeTarget; 188 | buildConfigurationList = 9AB8F5251E5A903200C7A98F /* Build configuration list for PBXNativeTarget "TanTanUITests" */; 189 | buildPhases = ( 190 | 9AB8F5121E5A903200C7A98F /* Sources */, 191 | 9AB8F5131E5A903200C7A98F /* Frameworks */, 192 | 9AB8F5141E5A903200C7A98F /* Resources */, 193 | ); 194 | buildRules = ( 195 | ); 196 | dependencies = ( 197 | 9AB8F5181E5A903200C7A98F /* PBXTargetDependency */, 198 | ); 199 | name = TanTanUITests; 200 | productName = TanTanUITests; 201 | productReference = 9AB8F5161E5A903200C7A98F /* TanTanUITests.xctest */; 202 | productType = "com.apple.product-type.bundle.ui-testing"; 203 | }; 204 | /* End PBXNativeTarget section */ 205 | 206 | /* Begin PBXProject section */ 207 | 9AB8F4EA1E5A903100C7A98F /* Project object */ = { 208 | isa = PBXProject; 209 | attributes = { 210 | LastUpgradeCheck = 0820; 211 | ORGANIZATIONNAME = cAibDe; 212 | TargetAttributes = { 213 | 9AB8F4F11E5A903100C7A98F = { 214 | CreatedOnToolsVersion = 8.2.1; 215 | DevelopmentTeam = K2WT69M66J; 216 | ProvisioningStyle = Automatic; 217 | }; 218 | 9AB8F50A1E5A903200C7A98F = { 219 | CreatedOnToolsVersion = 8.2.1; 220 | DevelopmentTeam = K2WT69M66J; 221 | ProvisioningStyle = Automatic; 222 | TestTargetID = 9AB8F4F11E5A903100C7A98F; 223 | }; 224 | 9AB8F5151E5A903200C7A98F = { 225 | CreatedOnToolsVersion = 8.2.1; 226 | DevelopmentTeam = K2WT69M66J; 227 | ProvisioningStyle = Automatic; 228 | TestTargetID = 9AB8F4F11E5A903100C7A98F; 229 | }; 230 | }; 231 | }; 232 | buildConfigurationList = 9AB8F4ED1E5A903100C7A98F /* Build configuration list for PBXProject "TanTan" */; 233 | compatibilityVersion = "Xcode 3.2"; 234 | developmentRegion = English; 235 | hasScannedForEncodings = 0; 236 | knownRegions = ( 237 | en, 238 | Base, 239 | ); 240 | mainGroup = 9AB8F4E91E5A903100C7A98F; 241 | productRefGroup = 9AB8F4F31E5A903100C7A98F /* Products */; 242 | projectDirPath = ""; 243 | projectRoot = ""; 244 | targets = ( 245 | 9AB8F4F11E5A903100C7A98F /* TanTan */, 246 | 9AB8F50A1E5A903200C7A98F /* TanTanTests */, 247 | 9AB8F5151E5A903200C7A98F /* TanTanUITests */, 248 | ); 249 | }; 250 | /* End PBXProject section */ 251 | 252 | /* Begin PBXResourcesBuildPhase section */ 253 | 9AB8F4F01E5A903100C7A98F /* Resources */ = { 254 | isa = PBXResourcesBuildPhase; 255 | buildActionMask = 2147483647; 256 | files = ( 257 | 9AB8F5051E5A903200C7A98F /* LaunchScreen.storyboard in Resources */, 258 | 9AB8F5021E5A903200C7A98F /* Assets.xcassets in Resources */, 259 | 9AB8F5001E5A903200C7A98F /* Main.storyboard in Resources */, 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | }; 263 | 9AB8F5091E5A903200C7A98F /* Resources */ = { 264 | isa = PBXResourcesBuildPhase; 265 | buildActionMask = 2147483647; 266 | files = ( 267 | ); 268 | runOnlyForDeploymentPostprocessing = 0; 269 | }; 270 | 9AB8F5141E5A903200C7A98F /* Resources */ = { 271 | isa = PBXResourcesBuildPhase; 272 | buildActionMask = 2147483647; 273 | files = ( 274 | ); 275 | runOnlyForDeploymentPostprocessing = 0; 276 | }; 277 | /* End PBXResourcesBuildPhase section */ 278 | 279 | /* Begin PBXSourcesBuildPhase section */ 280 | 9AB8F4EE1E5A903100C7A98F /* Sources */ = { 281 | isa = PBXSourcesBuildPhase; 282 | buildActionMask = 2147483647; 283 | files = ( 284 | 9AB8F52A1E5A90A500C7A98F /* TanTanView.m in Sources */, 285 | 9AB8F4FD1E5A903200C7A98F /* ViewController.m in Sources */, 286 | 9AB8F4FA1E5A903200C7A98F /* AppDelegate.m in Sources */, 287 | 9AB8F4F71E5A903200C7A98F /* main.m in Sources */, 288 | ); 289 | runOnlyForDeploymentPostprocessing = 0; 290 | }; 291 | 9AB8F5071E5A903200C7A98F /* Sources */ = { 292 | isa = PBXSourcesBuildPhase; 293 | buildActionMask = 2147483647; 294 | files = ( 295 | 9AB8F5101E5A903200C7A98F /* TanTanTests.m in Sources */, 296 | ); 297 | runOnlyForDeploymentPostprocessing = 0; 298 | }; 299 | 9AB8F5121E5A903200C7A98F /* Sources */ = { 300 | isa = PBXSourcesBuildPhase; 301 | buildActionMask = 2147483647; 302 | files = ( 303 | 9AB8F51B1E5A903200C7A98F /* TanTanUITests.m in Sources */, 304 | ); 305 | runOnlyForDeploymentPostprocessing = 0; 306 | }; 307 | /* End PBXSourcesBuildPhase section */ 308 | 309 | /* Begin PBXTargetDependency section */ 310 | 9AB8F50D1E5A903200C7A98F /* PBXTargetDependency */ = { 311 | isa = PBXTargetDependency; 312 | target = 9AB8F4F11E5A903100C7A98F /* TanTan */; 313 | targetProxy = 9AB8F50C1E5A903200C7A98F /* PBXContainerItemProxy */; 314 | }; 315 | 9AB8F5181E5A903200C7A98F /* PBXTargetDependency */ = { 316 | isa = PBXTargetDependency; 317 | target = 9AB8F4F11E5A903100C7A98F /* TanTan */; 318 | targetProxy = 9AB8F5171E5A903200C7A98F /* PBXContainerItemProxy */; 319 | }; 320 | /* End PBXTargetDependency section */ 321 | 322 | /* Begin PBXVariantGroup section */ 323 | 9AB8F4FE1E5A903200C7A98F /* Main.storyboard */ = { 324 | isa = PBXVariantGroup; 325 | children = ( 326 | 9AB8F4FF1E5A903200C7A98F /* Base */, 327 | ); 328 | name = Main.storyboard; 329 | sourceTree = ""; 330 | }; 331 | 9AB8F5031E5A903200C7A98F /* LaunchScreen.storyboard */ = { 332 | isa = PBXVariantGroup; 333 | children = ( 334 | 9AB8F5041E5A903200C7A98F /* Base */, 335 | ); 336 | name = LaunchScreen.storyboard; 337 | sourceTree = ""; 338 | }; 339 | /* End PBXVariantGroup section */ 340 | 341 | /* Begin XCBuildConfiguration section */ 342 | 9AB8F51D1E5A903200C7A98F /* Debug */ = { 343 | isa = XCBuildConfiguration; 344 | buildSettings = { 345 | ALWAYS_SEARCH_USER_PATHS = NO; 346 | CLANG_ANALYZER_NONNULL = YES; 347 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 348 | CLANG_CXX_LIBRARY = "libc++"; 349 | CLANG_ENABLE_MODULES = YES; 350 | CLANG_ENABLE_OBJC_ARC = YES; 351 | CLANG_WARN_BOOL_CONVERSION = YES; 352 | CLANG_WARN_CONSTANT_CONVERSION = YES; 353 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 354 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 355 | CLANG_WARN_EMPTY_BODY = YES; 356 | CLANG_WARN_ENUM_CONVERSION = YES; 357 | CLANG_WARN_INFINITE_RECURSION = YES; 358 | CLANG_WARN_INT_CONVERSION = YES; 359 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 360 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 361 | CLANG_WARN_UNREACHABLE_CODE = YES; 362 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 363 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 364 | COPY_PHASE_STRIP = NO; 365 | DEBUG_INFORMATION_FORMAT = dwarf; 366 | ENABLE_STRICT_OBJC_MSGSEND = YES; 367 | ENABLE_TESTABILITY = YES; 368 | GCC_C_LANGUAGE_STANDARD = gnu99; 369 | GCC_DYNAMIC_NO_PIC = NO; 370 | GCC_NO_COMMON_BLOCKS = YES; 371 | GCC_OPTIMIZATION_LEVEL = 0; 372 | GCC_PREPROCESSOR_DEFINITIONS = ( 373 | "DEBUG=1", 374 | "$(inherited)", 375 | ); 376 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 377 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 378 | GCC_WARN_UNDECLARED_SELECTOR = YES; 379 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 380 | GCC_WARN_UNUSED_FUNCTION = YES; 381 | GCC_WARN_UNUSED_VARIABLE = YES; 382 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 383 | MTL_ENABLE_DEBUG_INFO = YES; 384 | ONLY_ACTIVE_ARCH = YES; 385 | SDKROOT = iphoneos; 386 | TARGETED_DEVICE_FAMILY = "1,2"; 387 | }; 388 | name = Debug; 389 | }; 390 | 9AB8F51E1E5A903200C7A98F /* Release */ = { 391 | isa = XCBuildConfiguration; 392 | buildSettings = { 393 | ALWAYS_SEARCH_USER_PATHS = NO; 394 | CLANG_ANALYZER_NONNULL = YES; 395 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 396 | CLANG_CXX_LIBRARY = "libc++"; 397 | CLANG_ENABLE_MODULES = YES; 398 | CLANG_ENABLE_OBJC_ARC = YES; 399 | CLANG_WARN_BOOL_CONVERSION = YES; 400 | CLANG_WARN_CONSTANT_CONVERSION = YES; 401 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 402 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 403 | CLANG_WARN_EMPTY_BODY = YES; 404 | CLANG_WARN_ENUM_CONVERSION = YES; 405 | CLANG_WARN_INFINITE_RECURSION = YES; 406 | CLANG_WARN_INT_CONVERSION = YES; 407 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 408 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 409 | CLANG_WARN_UNREACHABLE_CODE = YES; 410 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 411 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 412 | COPY_PHASE_STRIP = NO; 413 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 414 | ENABLE_NS_ASSERTIONS = NO; 415 | ENABLE_STRICT_OBJC_MSGSEND = YES; 416 | GCC_C_LANGUAGE_STANDARD = gnu99; 417 | GCC_NO_COMMON_BLOCKS = YES; 418 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 419 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 420 | GCC_WARN_UNDECLARED_SELECTOR = YES; 421 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 422 | GCC_WARN_UNUSED_FUNCTION = YES; 423 | GCC_WARN_UNUSED_VARIABLE = YES; 424 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 425 | MTL_ENABLE_DEBUG_INFO = NO; 426 | SDKROOT = iphoneos; 427 | TARGETED_DEVICE_FAMILY = "1,2"; 428 | VALIDATE_PRODUCT = YES; 429 | }; 430 | name = Release; 431 | }; 432 | 9AB8F5201E5A903200C7A98F /* Debug */ = { 433 | isa = XCBuildConfiguration; 434 | buildSettings = { 435 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 436 | DEVELOPMENT_TEAM = K2WT69M66J; 437 | INFOPLIST_FILE = TanTan/Info.plist; 438 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 439 | PRODUCT_BUNDLE_IDENTIFIER = com.cAibDe.TanTan; 440 | PRODUCT_NAME = "$(TARGET_NAME)"; 441 | }; 442 | name = Debug; 443 | }; 444 | 9AB8F5211E5A903200C7A98F /* Release */ = { 445 | isa = XCBuildConfiguration; 446 | buildSettings = { 447 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 448 | DEVELOPMENT_TEAM = K2WT69M66J; 449 | INFOPLIST_FILE = TanTan/Info.plist; 450 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 451 | PRODUCT_BUNDLE_IDENTIFIER = com.cAibDe.TanTan; 452 | PRODUCT_NAME = "$(TARGET_NAME)"; 453 | }; 454 | name = Release; 455 | }; 456 | 9AB8F5231E5A903200C7A98F /* Debug */ = { 457 | isa = XCBuildConfiguration; 458 | buildSettings = { 459 | BUNDLE_LOADER = "$(TEST_HOST)"; 460 | DEVELOPMENT_TEAM = K2WT69M66J; 461 | INFOPLIST_FILE = TanTanTests/Info.plist; 462 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 463 | PRODUCT_BUNDLE_IDENTIFIER = com.cAibDe.TanTanTests; 464 | PRODUCT_NAME = "$(TARGET_NAME)"; 465 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TanTan.app/TanTan"; 466 | }; 467 | name = Debug; 468 | }; 469 | 9AB8F5241E5A903200C7A98F /* Release */ = { 470 | isa = XCBuildConfiguration; 471 | buildSettings = { 472 | BUNDLE_LOADER = "$(TEST_HOST)"; 473 | DEVELOPMENT_TEAM = K2WT69M66J; 474 | INFOPLIST_FILE = TanTanTests/Info.plist; 475 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 476 | PRODUCT_BUNDLE_IDENTIFIER = com.cAibDe.TanTanTests; 477 | PRODUCT_NAME = "$(TARGET_NAME)"; 478 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TanTan.app/TanTan"; 479 | }; 480 | name = Release; 481 | }; 482 | 9AB8F5261E5A903200C7A98F /* Debug */ = { 483 | isa = XCBuildConfiguration; 484 | buildSettings = { 485 | DEVELOPMENT_TEAM = K2WT69M66J; 486 | INFOPLIST_FILE = TanTanUITests/Info.plist; 487 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 488 | PRODUCT_BUNDLE_IDENTIFIER = com.cAibDe.TanTanUITests; 489 | PRODUCT_NAME = "$(TARGET_NAME)"; 490 | TEST_TARGET_NAME = TanTan; 491 | }; 492 | name = Debug; 493 | }; 494 | 9AB8F5271E5A903200C7A98F /* Release */ = { 495 | isa = XCBuildConfiguration; 496 | buildSettings = { 497 | DEVELOPMENT_TEAM = K2WT69M66J; 498 | INFOPLIST_FILE = TanTanUITests/Info.plist; 499 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 500 | PRODUCT_BUNDLE_IDENTIFIER = com.cAibDe.TanTanUITests; 501 | PRODUCT_NAME = "$(TARGET_NAME)"; 502 | TEST_TARGET_NAME = TanTan; 503 | }; 504 | name = Release; 505 | }; 506 | /* End XCBuildConfiguration section */ 507 | 508 | /* Begin XCConfigurationList section */ 509 | 9AB8F4ED1E5A903100C7A98F /* Build configuration list for PBXProject "TanTan" */ = { 510 | isa = XCConfigurationList; 511 | buildConfigurations = ( 512 | 9AB8F51D1E5A903200C7A98F /* Debug */, 513 | 9AB8F51E1E5A903200C7A98F /* Release */, 514 | ); 515 | defaultConfigurationIsVisible = 0; 516 | defaultConfigurationName = Release; 517 | }; 518 | 9AB8F51F1E5A903200C7A98F /* Build configuration list for PBXNativeTarget "TanTan" */ = { 519 | isa = XCConfigurationList; 520 | buildConfigurations = ( 521 | 9AB8F5201E5A903200C7A98F /* Debug */, 522 | 9AB8F5211E5A903200C7A98F /* Release */, 523 | ); 524 | defaultConfigurationIsVisible = 0; 525 | }; 526 | 9AB8F5221E5A903200C7A98F /* Build configuration list for PBXNativeTarget "TanTanTests" */ = { 527 | isa = XCConfigurationList; 528 | buildConfigurations = ( 529 | 9AB8F5231E5A903200C7A98F /* Debug */, 530 | 9AB8F5241E5A903200C7A98F /* Release */, 531 | ); 532 | defaultConfigurationIsVisible = 0; 533 | }; 534 | 9AB8F5251E5A903200C7A98F /* Build configuration list for PBXNativeTarget "TanTanUITests" */ = { 535 | isa = XCConfigurationList; 536 | buildConfigurations = ( 537 | 9AB8F5261E5A903200C7A98F /* Debug */, 538 | 9AB8F5271E5A903200C7A98F /* Release */, 539 | ); 540 | defaultConfigurationIsVisible = 0; 541 | }; 542 | /* End XCConfigurationList section */ 543 | }; 544 | rootObject = 9AB8F4EA1E5A903100C7A98F /* Project object */; 545 | } 546 | -------------------------------------------------------------------------------- /TanTan.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TanTan.xcodeproj/xcuserdata/caibde.xcuserdatad/xcschemes/TanTan.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /TanTan.xcodeproj/xcuserdata/caibde.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | TanTan.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 9AB8F4F11E5A903100C7A98F 16 | 17 | primary 18 | 19 | 20 | 9AB8F50A1E5A903200C7A98F 21 | 22 | primary 23 | 24 | 25 | 9AB8F5151E5A903200C7A98F 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /TanTan/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // TanTan 4 | // 5 | // Created by cAibDe on 2017/2/20. 6 | // Copyright © 2017年 cAibDe. 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 | -------------------------------------------------------------------------------- /TanTan/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // TanTan 4 | // 5 | // Created by cAibDe on 2017/2/20. 6 | // Copyright © 2017年 cAibDe. 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 | 24 | - (void)applicationWillResignActive:(UIApplication *)application { 25 | // 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. 26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 27 | } 28 | 29 | 30 | - (void)applicationDidEnterBackground:(UIApplication *)application { 31 | // 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. 32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 33 | } 34 | 35 | 36 | - (void)applicationWillEnterForeground:(UIApplication *)application { 37 | // 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. 38 | } 39 | 40 | 41 | - (void)applicationDidBecomeActive:(UIApplication *)application { 42 | // 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. 43 | } 44 | 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /TanTan/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 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /TanTan/Assets.xcassets/TanTanView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TanTanView.h 3 | // TanTan 4 | // 5 | // Created by cAibDe on 2017/2/20. 6 | // Copyright © 2017年 cAibDe. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol TanTanDelegate,TanTanDataSource; 12 | 13 | @interface TanTanView : UIView 14 | 15 | //代理 16 | @property (nonatomic, weak) iddelegate; 17 | //数据源 18 | @property (nonatomic, weak) iddataSource; 19 | //是否设置循环 20 | @property (nonatomic, assign) BOOL isCyclically; 21 | //展示出来的item数目 22 | @property (nonatomic, assign) NSInteger showItemsNumber; 23 | //设置偏移量 24 | @property (nonatomic, assign) CGSize offSet; 25 | //显示的第一个View 26 | @property (nonatomic, strong , readonly) UIView *topView; 27 | //刷新展示数据 28 | - (void)refreshData; 29 | 30 | - (void)viewDismissFromRight:(UIView *)view; 31 | 32 | - (void)viewDismissFromLeft:(UIView *)view; 33 | @end 34 | 35 | /*----------------------------------------------------------------*/ 36 | 37 | @protocol TanTanDataSource 38 | @required 39 | - (NSInteger)numberOfItemInTanTan:(TanTanView *)tantan; 40 | 41 | - (UIView *)tantan:(TanTanView *)tantan 42 | viewForItemAtIndex:(NSInteger)index 43 | reusingView:(UIView *)view; 44 | @end 45 | 46 | /*---------------------------------------------------------------*/ 47 | @protocol TanTanDelegate 48 | @optional 49 | - (void)tantan:(TanTanView *)tantan beforeSwipingItemAtIndex:(NSInteger)index; 50 | - (void)tantan:(TanTanView *)tantan didRemovedItemAtIndex:(NSInteger)index; 51 | - (void)tantan:(TanTanView *)tantan didLeftRemovedItemAtIndex:(NSInteger)index; 52 | - (void)tantan:(TanTanView *)tantan didRightRemovedItemAtIndex:(NSInteger)index; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /TanTan/Assets.xcassets/TanTanView.m: -------------------------------------------------------------------------------- 1 | // 2 | // TanTanView.m 3 | // TanTan 4 | // 5 | // Created by cAibDe on 2017/2/20. 6 | // Copyright © 2017年 cAibDe. All rights reserved. 7 | // 8 | 9 | #import "TanTanView.h" 10 | 11 | //判断当前view消失的一个距离设置 12 | static const CGFloat kActionMargin = 120; 13 | // how quickly the card shrinks. Higher = slower shrinking 14 | static const CGFloat kScaleStrength = 4; 15 | // upper bar for how much the card shrinks. Higher = shrinks less 16 | static const CGFloat kScaleMax = 0.93; 17 | // the maximum rotation allowed in radians. Higher = card can keep rotating longer 18 | static const CGFloat kRotationMax = 1.0; 19 | // strength of rotation. Higher = weaker rotation 20 | static const CGFloat kRotationStrength = 320; 21 | //旋转角度 22 | static const CGFloat kRotationAngle = M_PI / 8; 23 | @interface TanTanView () 24 | 25 | @property (nonatomic, strong) NSMutableArray *itemArray; 26 | //复用View 27 | @property (nonatomic, strong) UIView *reusingView; 28 | //拖拽手势 29 | @property (nonatomic, strong) UIPanGestureRecognizer *panGestureRecognizer; 30 | //原始点 31 | @property (nonatomic, assign) CGPoint originalPoint; 32 | //center.x的差值 33 | @property (nonatomic, assign) CGFloat xFromCenter; 34 | //center.y的差值 35 | @property (nonatomic, assign) CGFloat yFromCenter; 36 | @property (nonatomic, assign) NSInteger currentIndex; 37 | 38 | @property (nonatomic, assign) BOOL swipeEnded; 39 | 40 | @property (nonatomic, strong) UIButton *likeButton; 41 | 42 | @property (nonatomic, strong) UIButton *unlikeButton; 43 | 44 | @end 45 | @implementation TanTanView 46 | #pragma mark - 初始化 47 | - (instancetype)initWithFrame:(CGRect)frame{ 48 | self = [super initWithFrame:frame]; 49 | if (self) { 50 | [self setup]; 51 | } 52 | return self; 53 | } 54 | - (instancetype)initWithCoder:(NSCoder *)aDecoder{ 55 | self = [super initWithCoder:aDecoder]; 56 | if (self) { 57 | [self setup]; 58 | } 59 | return self; 60 | } 61 | #pragma mark - Setting 62 | - (void)setup{ 63 | _isCyclically = YES; 64 | _showItemsNumber = 5; 65 | _offSet = CGSizeMake(5, 5); 66 | _swipeEnded = YES; 67 | [self addGestureRecognizer:self.panGestureRecognizer]; 68 | } 69 | - (void)setIsCyclically:(BOOL)isCyclically{ 70 | _isCyclically = isCyclically; 71 | [self refreshData]; 72 | } 73 | - (void)setOffSet:(CGSize)offSet{ 74 | _offSet = offSet; 75 | [self refreshData]; 76 | } 77 | - (void)setShowItemsNumber:(NSInteger)showItemsNumber{ 78 | NSInteger itemNum = showItemsNumber; 79 | if ([self.dataSource respondsToSelector:@selector(numberOfItemInTanTan:)]) { 80 | itemNum = [self.dataSource numberOfItemInTanTan:self]; 81 | } 82 | _showItemsNumber = (itemNum>=showItemsNumber)?showItemsNumber:itemNum; 83 | [self refreshData]; 84 | } 85 | - (void)setDataSource:(id)dataSource{ 86 | _dataSource = dataSource; 87 | [self refreshData]; 88 | } 89 | #pragma mark - Lazy Load 90 | - (NSMutableArray *)itemArray{ 91 | if (_itemArray == nil) { 92 | _itemArray = [[NSMutableArray alloc]initWithCapacity:_showItemsNumber]; 93 | } 94 | return _itemArray; 95 | } 96 | - (UIPanGestureRecognizer *)panGestureRecognizer{ 97 | if (_panGestureRecognizer == nil) { 98 | _panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(dragAction:)]; 99 | } 100 | return _panGestureRecognizer; 101 | } 102 | - (UIView *)topView{ 103 | return [self.itemArray firstObject]; 104 | } 105 | 106 | #pragma mark - Methods 107 | - (void)refreshData{ 108 | _currentIndex = 0; 109 | _reusingView = nil; 110 | [self.itemArray removeAllObjects]; 111 | 112 | if ([self.dataSource respondsToSelector:@selector(numberOfItemInTanTan:)]) { 113 | NSInteger totoalNum = [self.dataSource numberOfItemInTanTan:self]; 114 | if (totoalNum>0) { 115 | if (totoalNum < _showItemsNumber) { 116 | _showItemsNumber = totoalNum; 117 | } 118 | if ([self.dataSource respondsToSelector:@selector(tantan:viewForItemAtIndex:reusingView:)]) { 119 | for (NSInteger i = 0; i<_showItemsNumber; i++) { 120 | UIView *view = [self.dataSource tantan:self viewForItemAtIndex:i reusingView:_reusingView]; 121 | 122 | //like 123 | UIButton *likebutton = [UIButton buttonWithType:UIButtonTypeCustom]; 124 | likebutton.frame = CGRectMake(0, view.frame.size.height-(view.frame.size.width/2), view.frame.size.width/2, view.frame.size.width/2); 125 | [likebutton setTitle:@"喜欢" forState:UIControlStateNormal]; 126 | [likebutton setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 127 | [likebutton addTarget:self action:@selector(likebuttonAction:) forControlEvents:UIControlEventTouchUpInside]; 128 | 129 | [view addSubview:likebutton]; 130 | //unlike 131 | UIButton *unlikebutton = [UIButton buttonWithType:UIButtonTypeCustom]; 132 | unlikebutton.frame = CGRectMake(view.frame.size.width/2, view.frame.size.height-(view.frame.size.width/2), view.frame.size.width/2, view.frame.size.width/2); 133 | [unlikebutton setTitle:@"不喜欢" forState:UIControlStateNormal]; 134 | [unlikebutton setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 135 | [unlikebutton addTarget:self action:@selector(unlikebuttonAction:) forControlEvents:UIControlEventTouchUpInside]; 136 | 137 | [view addSubview:unlikebutton]; 138 | 139 | 140 | [self.itemArray addObject:view]; 141 | } 142 | } 143 | } 144 | } 145 | [self layoutViews]; 146 | } 147 | #pragma mark - 手势相应方法 148 | - (void)dragAction:(UIPanGestureRecognizer *)gestureRecognizer{ 149 | 150 | if (self.itemArray.count <= 0) { 151 | return; 152 | } 153 | //获取数据源的总数 154 | NSInteger totalNum = [self.dataSource numberOfItemInTanTan:self]; 155 | if (_currentIndex > totalNum-1) { 156 | //数组越界的时候 157 | _currentIndex = 0; 158 | } 159 | 160 | if (self.swipeEnded) { 161 | self.swipeEnded = NO; 162 | if ([self.delegate respondsToSelector:@selector(tantan:beforeSwipingItemAtIndex:)]) { 163 | [self.delegate tantan:self beforeSwipingItemAtIndex:_currentIndex]; 164 | } 165 | } 166 | 167 | UIView *firstCard = [self.itemArray firstObject]; 168 | //获取当前center.x和之前的center.x的差值 169 | self.xFromCenter = [gestureRecognizer translationInView:firstCard].x; 170 | //获取当前center.y和之前的center.y的差值 171 | self.yFromCenter = [gestureRecognizer translationInView:firstCard].y; 172 | 173 | 174 | switch (gestureRecognizer.state) { 175 | case UIGestureRecognizerStateBegan: 176 | self.originalPoint = firstCard.center; 177 | break; 178 | case UIGestureRecognizerStateChanged: 179 | { 180 | //取相对较小的值 181 | CGFloat rotationStrength = MIN(self.xFromCenter/kRotationStrength, kRotationMax); 182 | //旋转角度 183 | CGFloat rotationAngel = rotationStrength * kRotationAngle; 184 | //比例 185 | CGFloat scale = MAX(1 - fabs(rotationStrength)/kScaleStrength, kScaleMax); 186 | //重置中点 187 | firstCard.center = CGPointMake(self.originalPoint.x + self.xFromCenter, 188 | self.originalPoint.y + self.yFromCenter); 189 | //旋转 190 | CGAffineTransform transform = CGAffineTransformMakeRotation(rotationAngel); 191 | //缩放 192 | CGAffineTransform scaleTransform = CGAffineTransformScale(transform, scale, scale); 193 | 194 | firstCard.transform = scaleTransform; 195 | } 196 | break; 197 | case UIGestureRecognizerStateEnded: 198 | { 199 | [self endSwiped:firstCard]; 200 | } 201 | break; 202 | default: 203 | break; 204 | } 205 | 206 | } 207 | - (void)endSwiped:(UIView *)view{ 208 | //当这个差值大于kActionMargin 让它从右边消失 209 | if (self.xFromCenter > kActionMargin) { 210 | [self viewDismissFromRight:view]; 211 | } 212 | //当这个差值小雨-kActionMargin 让它从左边消失 213 | else if (self.xFromCenter < -kActionMargin ){ 214 | [self viewDismissFromLeft:view]; 215 | } 216 | //其他情况恢复原来的位置 217 | else{ 218 | self.swipeEnded = YES; 219 | [UIView animateWithDuration:0.3 220 | animations: ^{ 221 | view.center = self.originalPoint; 222 | view.transform = CGAffineTransformMakeRotation(0); 223 | }]; 224 | } 225 | } 226 | - (void)viewDismissFromRight:(UIView *)view{ 227 | CGPoint finishPoint = CGPointMake(500, 2 * self.yFromCenter + self.originalPoint.y); 228 | 229 | //动画 230 | [UIView animateWithDuration:0.3 animations:^{ 231 | view.center = finishPoint; 232 | } completion:^(BOOL finished) { 233 | if ([self.delegate respondsToSelector:@selector(tantan:didRightRemovedItemAtIndex:)]) { 234 | [self.delegate tantan:self didRightRemovedItemAtIndex:_currentIndex]; 235 | } 236 | [self viewSwipAction:view]; 237 | }]; 238 | } 239 | - (void)viewDismissFromLeft:(UIView *)view{ 240 | CGPoint finishPoint = CGPointMake(-500, 2 * self.yFromCenter + self.originalPoint.y); 241 | //动画 242 | [UIView animateWithDuration:0.3 animations:^{ 243 | view.center = finishPoint; 244 | } completion:^(BOOL finished) { 245 | if ([self.delegate respondsToSelector:@selector(tantan:didLeftRemovedItemAtIndex:)]) { 246 | [self.delegate tantan:self didLeftRemovedItemAtIndex:_currentIndex]; 247 | } 248 | [self viewSwipAction:view]; 249 | }]; 250 | 251 | } 252 | - (void)viewSwipAction:(UIView *)view{ 253 | self.swipeEnded = YES; 254 | //移除view 重置属性 255 | view.transform = CGAffineTransformMakeRotation(0); 256 | view.center = self.originalPoint; 257 | _reusingView = view; 258 | [self.itemArray removeObject:view]; 259 | [view removeFromSuperview]; 260 | 261 | NSInteger totalNumber = [self.dataSource numberOfItemInTanTan:self]; 262 | UIView *newView; 263 | NSInteger newIndex = _currentIndex + _showItemsNumber; 264 | if (newIndex < totalNumber) { 265 | newView = [self.dataSource tantan:self viewForItemAtIndex:newIndex reusingView:_reusingView]; 266 | }else{ 267 | if (_isCyclically) { 268 | if (totalNumber == 1) { 269 | newIndex = 0; 270 | }else{ 271 | newIndex %= totalNumber; 272 | } 273 | newView = [self.dataSource tantan:self viewForItemAtIndex:newIndex reusingView:_reusingView]; 274 | } 275 | } 276 | if (newView) { 277 | if (CGSizeEqualToSize(self.frame.size, [self.itemArray.firstObject frame].size)) { 278 | newView.frame = [self.itemArray.firstObject frame]; 279 | }else{ 280 | newView.frame = CGRectMake([self.itemArray.firstObject frame].origin.x, 281 | [self.itemArray.firstObject frame].origin.y, 282 | self.frame.size.width, 283 | self.frame.size.height); 284 | } 285 | 286 | [self.itemArray addObject:newView]; 287 | } 288 | NSLog(@"%@",NSStringFromCGRect(newView.frame)); 289 | 290 | 291 | if ([self.delegate respondsToSelector:@selector(tantan:didLeftRemovedItemAtIndex:)]) { 292 | [self.delegate tantan:self didLeftRemovedItemAtIndex:_currentIndex]; 293 | } 294 | _currentIndex++; 295 | [self layoutViews]; 296 | } 297 | - (void)layoutViews{ 298 | NSInteger num = self.itemArray.count; 299 | if (num<=0) { 300 | return; 301 | } 302 | 303 | for (UIView *view in self.subviews) { 304 | [view removeFromSuperview]; 305 | } 306 | [self layoutIfNeeded]; 307 | 308 | CGFloat width = self.frame.size.width; 309 | CGFloat height = self.frame.size.height; 310 | //水平偏移量 311 | CGFloat horizonOffset = _offSet.width; 312 | //垂直偏移量 313 | CGFloat verticalOffset = _offSet.height; 314 | UIView *lastView = [self.itemArray lastObject]; 315 | CGFloat viewW = lastView.frame.size.width; 316 | CGFloat viewH = lastView.frame.size.height; 317 | CGFloat firstViewX = (width - viewW - (_showItemsNumber - 1)*fabs(horizonOffset))/2; 318 | 319 | if (horizonOffset < 0) { 320 | firstViewX += (_showItemsNumber-1) * fabs(horizonOffset); 321 | } 322 | CGFloat firstViewY = (height - viewH - (_showItemsNumber - 1) * fabs(verticalOffset))/2; 323 | if (verticalOffset < 0) { 324 | firstViewY += (_showItemsNumber - 1) * fabs(verticalOffset); 325 | } 326 | [UIView animateWithDuration:0.01 animations:^{ 327 | for (NSInteger i = 0; i 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 | -------------------------------------------------------------------------------- /TanTan/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 | -------------------------------------------------------------------------------- /TanTan/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 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /TanTan/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // TanTan 4 | // 5 | // Created by cAibDe on 2017/2/20. 6 | // Copyright © 2017年 cAibDe. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /TanTan/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // TanTan 4 | // 5 | // Created by cAibDe on 2017/2/20. 6 | // Copyright © 2017年 cAibDe. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | #import "TanTanView.h" 12 | 13 | #define kRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1] 14 | @interface ViewController () 15 | 16 | @property (nonatomic, strong) TanTanView *tantanView; 17 | 18 | 19 | @property (nonatomic, strong) NSMutableArray *dataArray; 20 | 21 | 22 | @end 23 | 24 | @implementation ViewController 25 | 26 | - (void)viewDidLoad { 27 | [super viewDidLoad]; 28 | // Do any additional setup after loading the view, typically from a nib. 29 | [self loadData]; 30 | 31 | [self creatTantanView]; 32 | 33 | } 34 | - (void)loadData{ 35 | for (int i = 0 ; i<4; i++) { 36 | [self.dataArray addObject:@(i)]; 37 | } 38 | 39 | } 40 | - (void)creatTantanView{ 41 | TanTanView *tantan = [[TanTanView alloc]initWithFrame:CGRectMake(0, 0, 300, 400)]; 42 | tantan.center = self.view.center; 43 | tantan.dataSource = self; 44 | tantan.delegate = self; 45 | self.tantanView = tantan; 46 | [self.view addSubview:tantan]; 47 | 48 | } 49 | #pragma mark - dataSourse 50 | 51 | - (NSInteger)numberOfItemInTanTan:(TanTanView *)tantan{ 52 | return self.dataArray.count; 53 | } 54 | - (UIView *)tantan:(TanTanView *)tantan viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{ 55 | 56 | UIView *firstView = view; 57 | if (firstView == nil) { 58 | CGSize size = tantan.frame.size; 59 | CGRect frame = CGRectMake(0, 0, size.width, size.height); 60 | firstView = [[UIView alloc]initWithFrame:frame]; 61 | 62 | 63 | } 64 | firstView.layer.backgroundColor = kRandomColor.CGColor; 65 | return firstView; 66 | 67 | // UILabel *label = (UILabel *)view; 68 | // if (label == nil) { 69 | // CGSize size = tantan.frame.size; 70 | // CGRect labelFrame = CGRectMake(0, 0, size.width - 30, size.height - 20); 71 | // label = [[UILabel alloc] initWithFrame:labelFrame]; 72 | // label.textAlignment = NSTextAlignmentCenter; 73 | // label.layer.cornerRadius = 5; 74 | // } 75 | // label.text = [self.dataArray[index] stringValue]; 76 | // label.layer.backgroundColor = kRandomColor.CGColor; 77 | // return label; 78 | } 79 | - (void)didReceiveMemoryWarning { 80 | [super didReceiveMemoryWarning]; 81 | // Dispose of any resources that can be recreated. 82 | } 83 | - (NSMutableArray *)dataArray{ 84 | if (_dataArray == nil ) { 85 | _dataArray = [NSMutableArray array]; 86 | } 87 | return _dataArray; 88 | } 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /TanTan/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TanTan 4 | // 5 | // Created by cAibDe on 2017/2/20. 6 | // Copyright © 2017年 cAibDe. 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 | -------------------------------------------------------------------------------- /TanTanTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /TanTanTests/TanTanTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // TanTanTests.m 3 | // TanTanTests 4 | // 5 | // Created by cAibDe on 2017/2/20. 6 | // Copyright © 2017年 cAibDe. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TanTanTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation TanTanTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /TanTanUITests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /TanTanUITests/TanTanUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // TanTanUITests.m 3 | // TanTanUITests 4 | // 5 | // Created by cAibDe on 2017/2/20. 6 | // Copyright © 2017年 cAibDe. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TanTanUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation TanTanUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------