├── Untitled.gif ├── 标签(swift) ├── 标签(swift) │ ├── Assets.xcassets │ │ ├── Contents.json │ │ ├── close.imageset │ │ │ ├── close@2x.png │ │ │ └── Contents.json │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── ViewController.swift │ ├── Info.plist │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── AppDelegate.swift │ └── ChannelViewController.swift └── 标签(swift).xcodeproj │ ├── project.xcworkspace │ └── contents.xcworkspacedata │ └── project.pbxproj ├── README.md ├── LICENSE └── .gitignore /Untitled.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coderLiuW/WLRearrangeView/HEAD/Untitled.gif -------------------------------------------------------------------------------- /标签(swift)/标签(swift)/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /标签(swift)/标签(swift)/Assets.xcassets/close.imageset/close@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coderLiuW/WLRearrangeView/HEAD/标签(swift)/标签(swift)/Assets.xcassets/close.imageset/close@2x.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Swift-WLRearrangeView 2 | 利用UICollectionView实现的拖拽排序 3 | 4 | 原理解析博文地址: 5 | http://www.jianshu.com/p/39ef303680fe 6 | 7 | ![image](https://raw.githubusercontent.com/wangliujiayou/Swift-dragLabel/master/Untitled.gif) 8 | 9 | 10 | -------------------------------------------------------------------------------- /标签(swift)/标签(swift).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /标签(swift)/标签(swift)/Assets.xcassets/close.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "close@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 | } -------------------------------------------------------------------------------- /标签(swift)/标签(swift)/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | } 43 | ], 44 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 wangliujiayou 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 | -------------------------------------------------------------------------------- /标签(swift)/标签(swift)/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // 标签(swift) 4 | // 5 | // Created by administrator on 2017/3/7. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | var selectedArr = ["推荐","河北","财经","娱乐","体育","社会","NBA","视频","汽车","图片","科技","军事","国际","数码","星座","电影","时尚","文化","游戏","教育","动漫","政务","纪录片","房产","佛学","股票","理财"] 14 | 15 | var recommendArr = ["有声","家居","电竞","美容","电视剧","搏击","健康","摄影","生活","旅游","韩流","探索","综艺","美食","育儿"] 16 | 17 | override func viewDidLoad() { 18 | super.viewDidLoad() 19 | 20 | 21 | } 22 | 23 | @IBAction func buttonClick(_ sender: Any) { 24 | 25 | let channelVC = ChannelViewController(a: selectedArr, b: recommendArr) 26 | channelVC.switchoverCallback = { 27 | 28 | (selectedArr, recommendArr, index) -> () in 29 | 30 | self.navigationItem.title = selectedArr[index] 31 | self.selectedArr = selectedArr 32 | self.recommendArr = recommendArr 33 | 34 | } 35 | navigationController?.pushViewController(channelVC, animated: true) 36 | 37 | } 38 | 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /标签(swift)/标签(swift)/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 | 38 | 39 | -------------------------------------------------------------------------------- /.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 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | -------------------------------------------------------------------------------- /标签(swift)/标签(swift)/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 | -------------------------------------------------------------------------------- /标签(swift)/标签(swift)/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // 标签(swift) 4 | // 5 | // Created by administrator on 2017/3/7. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /标签(swift)/标签(swift)/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 | -------------------------------------------------------------------------------- /标签(swift)/标签(swift).xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C3BCFDE41E6E9AE4000C6C8E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3BCFDE31E6E9AE4000C6C8E /* AppDelegate.swift */; }; 11 | C3BCFDE61E6E9AE4000C6C8E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3BCFDE51E6E9AE4000C6C8E /* ViewController.swift */; }; 12 | C3BCFDE91E6E9AE4000C6C8E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C3BCFDE71E6E9AE4000C6C8E /* Main.storyboard */; }; 13 | C3BCFDEB1E6E9AE4000C6C8E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C3BCFDEA1E6E9AE4000C6C8E /* Assets.xcassets */; }; 14 | C3BCFDEE1E6E9AE4000C6C8E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C3BCFDEC1E6E9AE4000C6C8E /* LaunchScreen.storyboard */; }; 15 | C3BCFDF61E6E9CD4000C6C8E /* ChannelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3BCFDF51E6E9CD4000C6C8E /* ChannelViewController.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | C3BCFDE01E6E9AE4000C6C8E /* 标签(swift).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "标签(swift).app"; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | C3BCFDE31E6E9AE4000C6C8E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | C3BCFDE51E6E9AE4000C6C8E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | C3BCFDE81E6E9AE4000C6C8E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | C3BCFDEA1E6E9AE4000C6C8E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | C3BCFDED1E6E9AE4000C6C8E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | C3BCFDEF1E6E9AE4000C6C8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | C3BCFDF51E6E9CD4000C6C8E /* ChannelViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChannelViewController.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | C3BCFDDD1E6E9AE4000C6C8E /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | C3BCFDD71E6E9AE4000C6C8E = { 41 | isa = PBXGroup; 42 | children = ( 43 | C3BCFDE21E6E9AE4000C6C8E /* 标签(swift) */, 44 | C3BCFDE11E6E9AE4000C6C8E /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | C3BCFDE11E6E9AE4000C6C8E /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | C3BCFDE01E6E9AE4000C6C8E /* 标签(swift).app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | C3BCFDE21E6E9AE4000C6C8E /* 标签(swift) */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | C3BCFDE31E6E9AE4000C6C8E /* AppDelegate.swift */, 60 | C3BCFDE51E6E9AE4000C6C8E /* ViewController.swift */, 61 | C3BCFDF51E6E9CD4000C6C8E /* ChannelViewController.swift */, 62 | C3BCFDE71E6E9AE4000C6C8E /* Main.storyboard */, 63 | C3BCFDEA1E6E9AE4000C6C8E /* Assets.xcassets */, 64 | C3BCFDEC1E6E9AE4000C6C8E /* LaunchScreen.storyboard */, 65 | C3BCFDEF1E6E9AE4000C6C8E /* Info.plist */, 66 | ); 67 | path = "标签(swift)"; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | C3BCFDDF1E6E9AE4000C6C8E /* 标签(swift) */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = C3BCFDF21E6E9AE4000C6C8E /* Build configuration list for PBXNativeTarget "标签(swift)" */; 76 | buildPhases = ( 77 | C3BCFDDC1E6E9AE4000C6C8E /* Sources */, 78 | C3BCFDDD1E6E9AE4000C6C8E /* Frameworks */, 79 | C3BCFDDE1E6E9AE4000C6C8E /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = "标签(swift)"; 86 | productName = "标签(swift)"; 87 | productReference = C3BCFDE01E6E9AE4000C6C8E /* 标签(swift).app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | C3BCFDD81E6E9AE4000C6C8E /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastSwiftUpdateCheck = 0810; 97 | LastUpgradeCheck = 0810; 98 | ORGANIZATIONNAME = WL; 99 | TargetAttributes = { 100 | C3BCFDDF1E6E9AE4000C6C8E = { 101 | CreatedOnToolsVersion = 8.1; 102 | ProvisioningStyle = Automatic; 103 | }; 104 | }; 105 | }; 106 | buildConfigurationList = C3BCFDDB1E6E9AE4000C6C8E /* Build configuration list for PBXProject "标签(swift)" */; 107 | compatibilityVersion = "Xcode 3.2"; 108 | developmentRegion = English; 109 | hasScannedForEncodings = 0; 110 | knownRegions = ( 111 | en, 112 | Base, 113 | ); 114 | mainGroup = C3BCFDD71E6E9AE4000C6C8E; 115 | productRefGroup = C3BCFDE11E6E9AE4000C6C8E /* Products */; 116 | projectDirPath = ""; 117 | projectRoot = ""; 118 | targets = ( 119 | C3BCFDDF1E6E9AE4000C6C8E /* 标签(swift) */, 120 | ); 121 | }; 122 | /* End PBXProject section */ 123 | 124 | /* Begin PBXResourcesBuildPhase section */ 125 | C3BCFDDE1E6E9AE4000C6C8E /* Resources */ = { 126 | isa = PBXResourcesBuildPhase; 127 | buildActionMask = 2147483647; 128 | files = ( 129 | C3BCFDEE1E6E9AE4000C6C8E /* LaunchScreen.storyboard in Resources */, 130 | C3BCFDEB1E6E9AE4000C6C8E /* Assets.xcassets in Resources */, 131 | C3BCFDE91E6E9AE4000C6C8E /* Main.storyboard in Resources */, 132 | ); 133 | runOnlyForDeploymentPostprocessing = 0; 134 | }; 135 | /* End PBXResourcesBuildPhase section */ 136 | 137 | /* Begin PBXSourcesBuildPhase section */ 138 | C3BCFDDC1E6E9AE4000C6C8E /* Sources */ = { 139 | isa = PBXSourcesBuildPhase; 140 | buildActionMask = 2147483647; 141 | files = ( 142 | C3BCFDE61E6E9AE4000C6C8E /* ViewController.swift in Sources */, 143 | C3BCFDF61E6E9CD4000C6C8E /* ChannelViewController.swift in Sources */, 144 | C3BCFDE41E6E9AE4000C6C8E /* AppDelegate.swift in Sources */, 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | /* End PBXSourcesBuildPhase section */ 149 | 150 | /* Begin PBXVariantGroup section */ 151 | C3BCFDE71E6E9AE4000C6C8E /* Main.storyboard */ = { 152 | isa = PBXVariantGroup; 153 | children = ( 154 | C3BCFDE81E6E9AE4000C6C8E /* Base */, 155 | ); 156 | name = Main.storyboard; 157 | sourceTree = ""; 158 | }; 159 | C3BCFDEC1E6E9AE4000C6C8E /* LaunchScreen.storyboard */ = { 160 | isa = PBXVariantGroup; 161 | children = ( 162 | C3BCFDED1E6E9AE4000C6C8E /* Base */, 163 | ); 164 | name = LaunchScreen.storyboard; 165 | sourceTree = ""; 166 | }; 167 | /* End PBXVariantGroup section */ 168 | 169 | /* Begin XCBuildConfiguration section */ 170 | C3BCFDF01E6E9AE4000C6C8E /* Debug */ = { 171 | isa = XCBuildConfiguration; 172 | buildSettings = { 173 | ALWAYS_SEARCH_USER_PATHS = NO; 174 | CLANG_ANALYZER_NONNULL = YES; 175 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 176 | CLANG_CXX_LIBRARY = "libc++"; 177 | CLANG_ENABLE_MODULES = YES; 178 | CLANG_ENABLE_OBJC_ARC = YES; 179 | CLANG_WARN_BOOL_CONVERSION = YES; 180 | CLANG_WARN_CONSTANT_CONVERSION = YES; 181 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 182 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 183 | CLANG_WARN_EMPTY_BODY = YES; 184 | CLANG_WARN_ENUM_CONVERSION = YES; 185 | CLANG_WARN_INFINITE_RECURSION = YES; 186 | CLANG_WARN_INT_CONVERSION = YES; 187 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 188 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 189 | CLANG_WARN_UNREACHABLE_CODE = YES; 190 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 191 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 192 | COPY_PHASE_STRIP = NO; 193 | DEBUG_INFORMATION_FORMAT = dwarf; 194 | ENABLE_STRICT_OBJC_MSGSEND = YES; 195 | ENABLE_TESTABILITY = YES; 196 | GCC_C_LANGUAGE_STANDARD = gnu99; 197 | GCC_DYNAMIC_NO_PIC = NO; 198 | GCC_NO_COMMON_BLOCKS = YES; 199 | GCC_OPTIMIZATION_LEVEL = 0; 200 | GCC_PREPROCESSOR_DEFINITIONS = ( 201 | "DEBUG=1", 202 | "$(inherited)", 203 | ); 204 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 205 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 206 | GCC_WARN_UNDECLARED_SELECTOR = YES; 207 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 208 | GCC_WARN_UNUSED_FUNCTION = YES; 209 | GCC_WARN_UNUSED_VARIABLE = YES; 210 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 211 | MTL_ENABLE_DEBUG_INFO = YES; 212 | ONLY_ACTIVE_ARCH = YES; 213 | SDKROOT = iphoneos; 214 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 215 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 216 | }; 217 | name = Debug; 218 | }; 219 | C3BCFDF11E6E9AE4000C6C8E /* Release */ = { 220 | isa = XCBuildConfiguration; 221 | buildSettings = { 222 | ALWAYS_SEARCH_USER_PATHS = NO; 223 | CLANG_ANALYZER_NONNULL = YES; 224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 225 | CLANG_CXX_LIBRARY = "libc++"; 226 | CLANG_ENABLE_MODULES = YES; 227 | CLANG_ENABLE_OBJC_ARC = YES; 228 | CLANG_WARN_BOOL_CONVERSION = YES; 229 | CLANG_WARN_CONSTANT_CONVERSION = YES; 230 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 231 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INFINITE_RECURSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 237 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 238 | CLANG_WARN_UNREACHABLE_CODE = YES; 239 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 240 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 241 | COPY_PHASE_STRIP = NO; 242 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 243 | ENABLE_NS_ASSERTIONS = NO; 244 | ENABLE_STRICT_OBJC_MSGSEND = YES; 245 | GCC_C_LANGUAGE_STANDARD = gnu99; 246 | GCC_NO_COMMON_BLOCKS = YES; 247 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 248 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 249 | GCC_WARN_UNDECLARED_SELECTOR = YES; 250 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 251 | GCC_WARN_UNUSED_FUNCTION = YES; 252 | GCC_WARN_UNUSED_VARIABLE = YES; 253 | IPHONEOS_DEPLOYMENT_TARGET = 10.1; 254 | MTL_ENABLE_DEBUG_INFO = NO; 255 | SDKROOT = iphoneos; 256 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 257 | VALIDATE_PRODUCT = YES; 258 | }; 259 | name = Release; 260 | }; 261 | C3BCFDF31E6E9AE4000C6C8E /* Debug */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 265 | INFOPLIST_FILE = "标签(swift)/Info.plist"; 266 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 267 | PRODUCT_BUNDLE_IDENTIFIER = "com.wangliu.---swift-"; 268 | PRODUCT_NAME = "$(TARGET_NAME)"; 269 | SWIFT_VERSION = 3.0; 270 | }; 271 | name = Debug; 272 | }; 273 | C3BCFDF41E6E9AE4000C6C8E /* Release */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 277 | INFOPLIST_FILE = "标签(swift)/Info.plist"; 278 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 279 | PRODUCT_BUNDLE_IDENTIFIER = "com.wangliu.---swift-"; 280 | PRODUCT_NAME = "$(TARGET_NAME)"; 281 | SWIFT_VERSION = 3.0; 282 | }; 283 | name = Release; 284 | }; 285 | /* End XCBuildConfiguration section */ 286 | 287 | /* Begin XCConfigurationList section */ 288 | C3BCFDDB1E6E9AE4000C6C8E /* Build configuration list for PBXProject "标签(swift)" */ = { 289 | isa = XCConfigurationList; 290 | buildConfigurations = ( 291 | C3BCFDF01E6E9AE4000C6C8E /* Debug */, 292 | C3BCFDF11E6E9AE4000C6C8E /* Release */, 293 | ); 294 | defaultConfigurationIsVisible = 0; 295 | defaultConfigurationName = Release; 296 | }; 297 | C3BCFDF21E6E9AE4000C6C8E /* Build configuration list for PBXNativeTarget "标签(swift)" */ = { 298 | isa = XCConfigurationList; 299 | buildConfigurations = ( 300 | C3BCFDF31E6E9AE4000C6C8E /* Debug */, 301 | C3BCFDF41E6E9AE4000C6C8E /* Release */, 302 | ); 303 | defaultConfigurationIsVisible = 0; 304 | }; 305 | /* End XCConfigurationList section */ 306 | }; 307 | rootObject = C3BCFDD81E6E9AE4000C6C8E /* Project object */; 308 | } 309 | -------------------------------------------------------------------------------- /标签(swift)/标签(swift)/ChannelViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChannelViewController.swift 3 | // 标签(swift) 4 | // 5 | // Created by administrator on 2017/3/7. 6 | // Copyright © 2017年 WL. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | 12 | private let SCREEN_WIDTH = UIScreen.main.bounds.width 13 | private let SCREEN_HEIGHT = UIScreen.main.bounds.height 14 | 15 | private let ChannelViewCellIdentifier = "ChannelViewCellIdentifier" 16 | private let ChannelViewHeaderIdentifier = "ChannelViewHeaderIdentifier" 17 | 18 | let itemW: CGFloat = (SCREEN_WIDTH - 100) * 0.25 19 | 20 | class ChannelViewController: UIViewController { 21 | 22 | var switchoverCallback: ((_ selectedArr: [String], _ recommendArr: [String], _ index: Int) -> ())? 23 | 24 | var headerArr = [["切换频道","点击添加更多频道"],["长按拖动排序","点击添加更多频道"]] 25 | var selectedArr = ["推荐","河北","财经","娱乐","体育","社会","NBA","视频","汽车","图片","科技","军事","国际","数码","星座","电影","时尚","文化","游戏","教育","动漫","政务","纪录片","房产","佛学","股票","理财"] 26 | 27 | var recommendArr = ["有声","家居","电竞","美容","电视剧","搏击","健康","摄影","生活","旅游","韩流","探索","综艺","美食","育儿"] 28 | 29 | var isEdite = false 30 | 31 | var indexPath: IndexPath? 32 | var targetIndexPath: IndexPath? 33 | 34 | 35 | init(a:[String], b:[String]) { 36 | selectedArr = a 37 | recommendArr = b 38 | super.init(nibName: nil, bundle: nil) 39 | 40 | 41 | } 42 | 43 | required init?(coder aDecoder: NSCoder) { 44 | fatalError("init(coder:) has not been implemented") 45 | } 46 | 47 | //MARK: - 懒加载collectionView 48 | private lazy var collectionView: UICollectionView = { 49 | 50 | 51 | let clv = UICollectionView(frame: self.view.frame, collectionViewLayout: ChannelViewLayout()) 52 | clv.backgroundColor = UIColor.white 53 | clv.delegate = self 54 | clv.dataSource = self 55 | clv.register(ChannelViewCell.self, forCellWithReuseIdentifier: ChannelViewCellIdentifier) 56 | clv.register(ChannelHeaderView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: ChannelViewHeaderIdentifier) 57 | let longPress = UILongPressGestureRecognizer(target: self, action: #selector(longPressGesture(_:))) 58 | clv.addGestureRecognizer(longPress) 59 | 60 | return clv 61 | }() 62 | 63 | private lazy var dragingItem: ChannelViewCell = { 64 | 65 | let cell = ChannelViewCell(frame: CGRect(x: 0, y: 0, width: itemW, height: itemW * 0.5)) 66 | cell.isHidden = true 67 | return cell 68 | }() 69 | 70 | 71 | override func viewDidLoad() { 72 | super.viewDidLoad() 73 | navigationItem.title = "频道管理" 74 | view.addSubview(collectionView) 75 | collectionView.addSubview(dragingItem) 76 | } 77 | 78 | //MARK: - 长按动作 79 | func longPressGesture(_ tap: UILongPressGestureRecognizer) { 80 | 81 | if !isEdite { 82 | 83 | isEdite = !isEdite 84 | collectionView.reloadData() 85 | return 86 | } 87 | let point = tap.location(in: collectionView) 88 | 89 | switch tap.state { 90 | case UIGestureRecognizerState.began: 91 | dragBegan(point: point) 92 | case UIGestureRecognizerState.changed: 93 | drageChanged(point: point) 94 | case UIGestureRecognizerState.ended: 95 | drageEnded(point: point) 96 | case UIGestureRecognizerState.cancelled: 97 | drageEnded(point: point) 98 | default: break 99 | 100 | } 101 | 102 | } 103 | 104 | //MARK: - 长按开始 105 | private func dragBegan(point: CGPoint) { 106 | 107 | 108 | 109 | indexPath = collectionView.indexPathForItem(at: point) 110 | if indexPath == nil || (indexPath?.section)! > 0 || indexPath?.item == 0 111 | {return} 112 | 113 | let item = collectionView.cellForItem(at: indexPath!) as? ChannelViewCell 114 | item?.isHidden = true 115 | dragingItem.isHidden = false 116 | dragingItem.frame = (item?.frame)! 117 | dragingItem.text = item!.text 118 | dragingItem.transform = CGAffineTransform(scaleX: 1.1, y: 1.1) 119 | } 120 | //MARK: - 长按过程 121 | private func drageChanged(point: CGPoint) { 122 | if indexPath == nil || (indexPath?.section)! > 0 || indexPath?.item == 0 {return} 123 | dragingItem.center = point 124 | targetIndexPath = collectionView.indexPathForItem(at: point) 125 | if targetIndexPath == nil || (targetIndexPath?.section)! > 0 || indexPath == targetIndexPath || targetIndexPath?.item == 0 {return} 126 | // 更新数据 127 | let obj = selectedArr[indexPath!.item] 128 | selectedArr.remove(at: indexPath!.row) 129 | selectedArr.insert(obj, at: targetIndexPath!.item) 130 | //交换位置 131 | collectionView.moveItem(at: indexPath!, to: targetIndexPath!) 132 | indexPath = targetIndexPath 133 | } 134 | 135 | //MARK: - 长按结束 136 | private func drageEnded(point: CGPoint) { 137 | 138 | if indexPath == nil || (indexPath?.section)! > 0 || indexPath?.item == 0 {return} 139 | let endCell = collectionView.cellForItem(at: indexPath!) 140 | 141 | UIView.animate(withDuration: 0.25, animations: { 142 | 143 | self.dragingItem.transform = CGAffineTransform.identity 144 | self.dragingItem.center = (endCell?.center)! 145 | 146 | }, completion: { 147 | 148 | (finish) -> () in 149 | 150 | endCell?.isHidden = false 151 | self.dragingItem.isHidden = true 152 | self.indexPath = nil 153 | 154 | }) 155 | 156 | } 157 | 158 | 159 | 160 | 161 | } 162 | 163 | //MARK: - UICollectionViewDelegate 方法 164 | extension ChannelViewController: UICollectionViewDelegate, UICollectionViewDataSource { 165 | 166 | func numberOfSections(in collectionView: UICollectionView) -> Int { 167 | return 2 168 | } 169 | 170 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 171 | 172 | return section == 0 ? selectedArr.count : recommendArr.count 173 | 174 | } 175 | 176 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 177 | 178 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ChannelViewCellIdentifier, for: indexPath) as! ChannelViewCell 179 | 180 | cell.text = indexPath.section == 0 ? selectedArr[indexPath.item] : recommendArr[indexPath.item] 181 | cell.edite = (indexPath.section == 0 && indexPath.item == 0) ? false : isEdite 182 | 183 | return cell 184 | } 185 | 186 | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 187 | 188 | 189 | 190 | if indexPath.section > 0 { 191 | 192 | // 更新数据 193 | let obj = recommendArr[indexPath.item] 194 | recommendArr.remove(at: indexPath.item) 195 | selectedArr.append(obj) 196 | collectionView.moveItem(at: indexPath, to: NSIndexPath(item: selectedArr.count - 1, section: 0) as IndexPath) 197 | 198 | } else { 199 | 200 | if isEdite { 201 | 202 | if indexPath.item == 0 {return} 203 | // 更新数据 204 | let obj = selectedArr[indexPath.item] 205 | selectedArr.remove(at: indexPath.item) 206 | recommendArr.insert(obj, at: 0) 207 | collectionView.moveItem(at: indexPath, to: NSIndexPath(item: 0, section: 1) as IndexPath) 208 | 209 | } else { 210 | 211 | if switchoverCallback != nil { 212 | 213 | switchoverCallback!(selectedArr, recommendArr, indexPath.item) 214 | _ = navigationController?.popViewController(animated: true) 215 | } 216 | } 217 | } 218 | 219 | 220 | 221 | } 222 | 223 | 224 | func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { 225 | 226 | let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: ChannelViewHeaderIdentifier, for: indexPath) as! ChannelHeaderView 227 | header.text = isEdite ? headerArr[1][indexPath.section] : headerArr[0][indexPath.section] 228 | header.button.isSelected = isEdite 229 | if indexPath.section > 0 {header.button.isHidden = true} else {header.button.isHidden = false} 230 | 231 | 232 | header.clickCallback = {[weak self] in 233 | 234 | self?.isEdite = !(self?.isEdite)! 235 | collectionView.reloadData() 236 | 237 | } 238 | 239 | return header 240 | 241 | } 242 | 243 | } 244 | 245 | 246 | //MARK: - 自定义cell 247 | class ChannelViewCell: UICollectionViewCell { 248 | 249 | var edite = true { 250 | didSet { 251 | 252 | imageView.isHidden = !edite 253 | } 254 | } 255 | 256 | var text: String? { 257 | 258 | didSet { 259 | 260 | label.text = text 261 | 262 | } 263 | 264 | } 265 | 266 | override init(frame: CGRect) { 267 | super.init(frame: frame) 268 | 269 | setupUI() 270 | } 271 | 272 | private func setupUI() { 273 | 274 | contentView.addSubview(label) 275 | label.addSubview(imageView) 276 | contentView.layer.cornerRadius = 5 277 | contentView.layer.borderWidth = 1 278 | contentView.layer.borderColor = UIColor.lightGray.cgColor 279 | 280 | } 281 | 282 | private lazy var label: UILabel = { 283 | 284 | let label = UILabel(frame: self.bounds) 285 | label.textAlignment = NSTextAlignment.center 286 | label.font = UIFont.systemFont(ofSize: 15) 287 | return label 288 | }() 289 | 290 | private lazy var imageView: UIImageView = { 291 | 292 | let image = UIImageView(frame: CGRect(x: 2, y: 2, width: 10, height: 10)) 293 | image.image = UIImage(named: "close") 294 | image.isHidden = true 295 | return image 296 | 297 | }() 298 | 299 | required init?(coder aDecoder: NSCoder) { 300 | fatalError("init(coder:) has not been implemented") 301 | } 302 | 303 | } 304 | //MARK: - 自定义头视图 305 | class ChannelHeaderView: UICollectionReusableView { 306 | 307 | var clickCallback: (() -> ())? 308 | 309 | var text: String? { 310 | 311 | didSet { 312 | 313 | label.text = text 314 | 315 | } 316 | 317 | } 318 | 319 | override init(frame: CGRect) { 320 | super.init(frame: frame) 321 | 322 | setupUI() 323 | } 324 | 325 | private func setupUI() { 326 | 327 | addSubview(label) 328 | addSubview(button) 329 | backgroundColor = UIColor.groupTableViewBackground 330 | } 331 | 332 | func buttonClick() { 333 | 334 | if (clickCallback != nil) { clickCallback!() } 335 | } 336 | 337 | 338 | private lazy var label: UILabel = { 339 | 340 | let label = UILabel(frame: self.bounds) 341 | label.frame.origin.x = 20 342 | return label 343 | }() 344 | 345 | lazy var button: UIButton = { 346 | 347 | let btn = UIButton(type: UIButtonType.custom) 348 | btn.setTitle("编辑", for: .normal) 349 | btn.setTitle("完成", for: .selected) 350 | btn.setTitleColor(UIColor.blue, for: .normal) 351 | btn.titleLabel?.font = UIFont.systemFont(ofSize: 15) 352 | btn.frame = CGRect(x: SCREEN_WIDTH - 80, y: 0, width: 80, height: self.frame.height) 353 | btn.addTarget(self, action: #selector(buttonClick), for: .touchUpInside) 354 | return btn 355 | 356 | }() 357 | 358 | 359 | required init?(coder aDecoder: NSCoder) { 360 | fatalError("init(coder:) has not been implemented") 361 | } 362 | 363 | } 364 | //MARK: - 自定义布局属性 365 | class ChannelViewLayout: UICollectionViewFlowLayout { 366 | 367 | override func prepare() { 368 | super.prepare() 369 | 370 | headerReferenceSize = CGSize(width: SCREEN_WIDTH, height: 40) 371 | itemSize = CGSize(width: itemW, height: itemW * 0.5) 372 | minimumLineSpacing = 15 373 | minimumInteritemSpacing = 20 374 | sectionInset = UIEdgeInsets(top: 10, left: 20, bottom: 10, right: 20) 375 | 376 | } 377 | 378 | } 379 | --------------------------------------------------------------------------------