Commit 8e77cf68ac4a34e6b5eeb086adfde4498968affa
Merge branch 'master' of http://bj.gitlab.cnlive.com/ios-team/CNLiveMateCode
# Conflicts: # Podfile # metaCode.xcodeproj/project.pbxproj # metaCode/Classes/Common/Base/CNLiveBaseViewController.swift # metaCode/Classes/Other/ViewController.swift
Showing
33 changed files
with
2530 additions
and
10 deletions
Podfile
| ... | ... | @@ -11,11 +11,8 @@ target 'metaCode' do |
| 11 | 11 | # Comment the next line if you don't want to use dynamic frameworks |
| 12 | 12 | use_frameworks! |
| 13 | 13 | |
| 14 | -# pod 'Alamofire' | |
| 15 | -# pod 'Moya' | |
| 16 | -# pod 'SwiftyJSON' | |
| 17 | -# pod 'YYCategories' | |
| 18 | -# pod 'CryptoSwift' | |
| 14 | + pod 'YYCategories' | |
| 15 | + | |
| 19 | 16 | # Pods for metaCode |
| 20 | 17 | |
| 21 | 18 | pod 'AFNetworking' | ... | ... |
metaCode.xcodeproj/project.pbxproj
| ... | ... | @@ -12,7 +12,21 @@ |
| 12 | 12 | 796398932A260C0100D045EB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7963988C2A260C0100D045EB /* ViewController.swift */; }; |
| 13 | 13 | 796398942A260C0100D045EB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7963988D2A260C0100D045EB /* AppDelegate.swift */; }; |
| 14 | 14 | 7963989D2A260E6200D045EB /* CNLiveBaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7963989C2A260E6200D045EB /* CNLiveBaseViewController.swift */; }; |
| 15 | - 79A68C542A27307900DC3B43 /* CNLiveConfigMacro.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79A68C532A27307900DC3B43 /* CNLiveConfigMacro.swift */; }; | |
| 15 | + 79A68C4A2A26E6CE00DC3B43 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79A68C492A26E6CE00DC3B43 /* Network.swift */; }; | |
| 16 | + 79A68C4C2A26EA6000DC3B43 /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79A68C4B2A26EA6000DC3B43 /* API.swift */; }; | |
| 17 | + 7CD675202A26F805008354C1 /* CNLiveConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD6751F2A26F805008354C1 /* CNLiveConfig.swift */; }; | |
| 18 | + 7CD675292A270F6A008354C1 /* WJColorChange.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CD675282A270F6A008354C1 /* WJColorChange.m */; }; | |
| 19 | + 7CD6752E2A271FE6008354C1 /* CNHexColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD6752D2A271FE6008354C1 /* CNHexColor.swift */; }; | |
| 20 | + 7CD6753C2A2740B0008354C1 /* CNBottomPayMoneyRemindView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD675372A2740B0008354C1 /* CNBottomPayMoneyRemindView.swift */; }; | |
| 21 | + 7CD6753D2A2740B0008354C1 /* CNMainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD675382A2740B0008354C1 /* CNMainView.swift */; }; | |
| 22 | + 7CD6753E2A2740B0008354C1 /* CNPayMoneyCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD675392A2740B0008354C1 /* CNPayMoneyCodeView.swift */; }; | |
| 23 | + 7CD6753F2A2740B0008354C1 /* CNTopCollectMoneyRemindView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD6753A2A2740B0008354C1 /* CNTopCollectMoneyRemindView.swift */; }; | |
| 24 | + 7CD675402A2740B0008354C1 /* CNCollectMoneyCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD6753B2A2740B0008354C1 /* CNCollectMoneyCodeView.swift */; }; | |
| 25 | + 7CD675422A2740F8008354C1 /* CNCustomIndexView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD675412A2740F8008354C1 /* CNCustomIndexView.swift */; }; | |
| 26 | + 7CD675472A274167008354C1 /* NewPagedFlowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CD675442A274167008354C1 /* NewPagedFlowView.m */; }; | |
| 27 | + 7CD675482A274167008354C1 /* PGIndexBannerSubiew.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CD675462A274167008354C1 /* PGIndexBannerSubiew.m */; }; | |
| 28 | + 7CD6754F2A2840B9008354C1 /* CNMetaCodeHomePageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD6754E2A2840B9008354C1 /* CNMetaCodeHomePageController.swift */; }; | |
| 29 | + 7CD675522A29C04B008354C1 /* CNLiveConstant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CD675512A29C04B008354C1 /* CNLiveConstant.swift */; }; | |
| 16 | 30 | 818163C32A25CFCC00579C86 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 818163C12A25CFCC00579C86 /* Main.storyboard */; }; |
| 17 | 31 | 818163C52A25CFCF00579C86 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 818163C42A25CFCF00579C86 /* Assets.xcassets */; }; |
| 18 | 32 | 818163C82A25CFCF00579C86 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 818163C62A25CFCF00579C86 /* LaunchScreen.storyboard */; }; |
| ... | ... | @@ -50,7 +64,23 @@ |
| 50 | 64 | 7963988D2A260C0100D045EB /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; |
| 51 | 65 | 7963989C2A260E6200D045EB /* CNLiveBaseViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CNLiveBaseViewController.swift; sourceTree = "<group>"; }; |
| 52 | 66 | 79A68C512A26F59C00DC3B43 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = metaCode/Info.plist; sourceTree = "<group>"; }; |
| 53 | - 79A68C532A27307900DC3B43 /* CNLiveConfigMacro.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveConfigMacro.swift; sourceTree = "<group>"; }; | |
| 67 | + 7CD6751F2A26F805008354C1 /* CNLiveConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CNLiveConfig.swift; path = ../../../../Documents/CNLiveConfig.swift; sourceTree = "<group>"; }; | |
| 68 | + 7CD675262A270F69008354C1 /* metaCode-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "metaCode-Bridging-Header.h"; sourceTree = "<group>"; }; | |
| 69 | + 7CD675272A270F6A008354C1 /* WJColorChange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WJColorChange.h; sourceTree = "<group>"; }; | |
| 70 | + 7CD675282A270F6A008354C1 /* WJColorChange.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WJColorChange.m; sourceTree = "<group>"; }; | |
| 71 | + 7CD6752D2A271FE6008354C1 /* CNHexColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CNHexColor.swift; path = ../../../../CNLiveDigitalRMBHomeDeom/CNLiveDigitalRMBHomeDeom/Classes/NewPagedFlowView/CNHexColor.swift; sourceTree = "<group>"; }; | |
| 72 | + 7CD675372A2740B0008354C1 /* CNBottomPayMoneyRemindView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CNBottomPayMoneyRemindView.swift; sourceTree = "<group>"; }; | |
| 73 | + 7CD675382A2740B0008354C1 /* CNMainView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CNMainView.swift; sourceTree = "<group>"; }; | |
| 74 | + 7CD675392A2740B0008354C1 /* CNPayMoneyCodeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CNPayMoneyCodeView.swift; sourceTree = "<group>"; }; | |
| 75 | + 7CD6753A2A2740B0008354C1 /* CNTopCollectMoneyRemindView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CNTopCollectMoneyRemindView.swift; sourceTree = "<group>"; }; | |
| 76 | + 7CD6753B2A2740B0008354C1 /* CNCollectMoneyCodeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CNCollectMoneyCodeView.swift; sourceTree = "<group>"; }; | |
| 77 | + 7CD675412A2740F8008354C1 /* CNCustomIndexView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNCustomIndexView.swift; sourceTree = "<group>"; }; | |
| 78 | + 7CD675432A274167008354C1 /* PGIndexBannerSubiew.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PGIndexBannerSubiew.h; sourceTree = "<group>"; }; | |
| 79 | + 7CD675442A274167008354C1 /* NewPagedFlowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NewPagedFlowView.m; sourceTree = "<group>"; }; | |
| 80 | + 7CD675452A274167008354C1 /* NewPagedFlowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NewPagedFlowView.h; sourceTree = "<group>"; }; | |
| 81 | + 7CD675462A274167008354C1 /* PGIndexBannerSubiew.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PGIndexBannerSubiew.m; sourceTree = "<group>"; }; | |
| 82 | + 7CD6754E2A2840B9008354C1 /* CNMetaCodeHomePageController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CNMetaCodeHomePageController.swift; sourceTree = "<group>"; }; | |
| 83 | + 7CD675512A29C04B008354C1 /* CNLiveConstant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveConstant.swift; sourceTree = "<group>"; }; | |
| 54 | 84 | 818163B82A25CFCC00579C86 /* metaCode.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = metaCode.app; sourceTree = BUILT_PRODUCTS_DIR; }; |
| 55 | 85 | 818163C22A25CFCC00579C86 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; }; |
| 56 | 86 | 818163C42A25CFCF00579C86 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; |
| ... | ... | @@ -109,6 +139,8 @@ |
| 109 | 139 | 7963988A2A260B3300D045EB /* Classes */ = { |
| 110 | 140 | isa = PBXGroup; |
| 111 | 141 | children = ( |
| 142 | + 7CD675502A29C036008354C1 /* Constant */, | |
| 143 | + 7CD6752C2A271FB1008354C1 /* Extensions */, | |
| 112 | 144 | 796398912A260C0100D045EB /* Common */, |
| 113 | 145 | 796398922A260C0100D045EB /* Config */, |
| 114 | 146 | 796398902A260C0100D045EB /* Main */, |
| ... | ... | @@ -138,6 +170,13 @@ |
| 138 | 170 | 7963988F2A260C0100D045EB /* Vendors */ = { |
| 139 | 171 | isa = PBXGroup; |
| 140 | 172 | children = ( |
| 173 | + 7CD675272A270F6A008354C1 /* WJColorChange.h */, | |
| 174 | + 7CD675282A270F6A008354C1 /* WJColorChange.m */, | |
| 175 | + 7CD675262A270F69008354C1 /* metaCode-Bridging-Header.h */, | |
| 176 | + 7CD675452A274167008354C1 /* NewPagedFlowView.h */, | |
| 177 | + 7CD675442A274167008354C1 /* NewPagedFlowView.m */, | |
| 178 | + 7CD675432A274167008354C1 /* PGIndexBannerSubiew.h */, | |
| 179 | + 7CD675462A274167008354C1 /* PGIndexBannerSubiew.m */, | |
| 141 | 180 | ); |
| 142 | 181 | path = Vendors; |
| 143 | 182 | sourceTree = "<group>"; |
| ... | ... | @@ -145,6 +184,7 @@ |
| 145 | 184 | 796398902A260C0100D045EB /* Main */ = { |
| 146 | 185 | isa = PBXGroup; |
| 147 | 186 | children = ( |
| 187 | + 7CD675212A26F844008354C1 /* HomePage */, | |
| 148 | 188 | ); |
| 149 | 189 | path = Main; |
| 150 | 190 | sourceTree = "<group>"; |
| ... | ... | @@ -160,7 +200,8 @@ |
| 160 | 200 | 796398922A260C0100D045EB /* Config */ = { |
| 161 | 201 | isa = PBXGroup; |
| 162 | 202 | children = ( |
| 163 | - 79A68C532A27307900DC3B43 /* CNLiveConfigMacro.swift */, | |
| 203 | + | |
| 204 | + 7CD6751F2A26F805008354C1 /* CNLiveConfig.swift */, | |
| 164 | 205 | ); |
| 165 | 206 | path = Config; |
| 166 | 207 | sourceTree = "<group>"; |
| ... | ... | @@ -183,6 +224,65 @@ |
| 183 | 224 | path = Base; |
| 184 | 225 | sourceTree = "<group>"; |
| 185 | 226 | }; |
| 227 | + | |
| 228 | + 7963989E2A260E7600D045EB /* Network */ = { | |
| 229 | + isa = PBXGroup; | |
| 230 | + children = ( | |
| 231 | + 79A68C492A26E6CE00DC3B43 /* Network.swift */, | |
| 232 | + 79A68C4B2A26EA6000DC3B43 /* API.swift */, | |
| 233 | + ); | |
| 234 | + path = Network; | |
| 235 | + sourceTree = "<group>"; | |
| 236 | + }; | |
| 237 | + 7CD675212A26F844008354C1 /* HomePage */ = { | |
| 238 | + isa = PBXGroup; | |
| 239 | + children = ( | |
| 240 | + 7CD6754D2A2840B9008354C1 /* Controller */, | |
| 241 | + 7CD675232A26F8F8008354C1 /* View */, | |
| 242 | + ); | |
| 243 | + name = HomePage; | |
| 244 | + sourceTree = "<group>"; | |
| 245 | + }; | |
| 246 | + 7CD675232A26F8F8008354C1 /* View */ = { | |
| 247 | + isa = PBXGroup; | |
| 248 | + children = ( | |
| 249 | + 7CD675372A2740B0008354C1 /* CNBottomPayMoneyRemindView.swift */, | |
| 250 | + 7CD6753B2A2740B0008354C1 /* CNCollectMoneyCodeView.swift */, | |
| 251 | + 7CD675382A2740B0008354C1 /* CNMainView.swift */, | |
| 252 | + 7CD675392A2740B0008354C1 /* CNPayMoneyCodeView.swift */, | |
| 253 | + 7CD6753A2A2740B0008354C1 /* CNTopCollectMoneyRemindView.swift */, | |
| 254 | + 7CD675412A2740F8008354C1 /* CNCustomIndexView.swift */, | |
| 255 | + ); | |
| 256 | + name = View; | |
| 257 | + path = HomePage/View; | |
| 258 | + sourceTree = "<group>"; | |
| 259 | + }; | |
| 260 | + 7CD6752C2A271FB1008354C1 /* Extensions */ = { | |
| 261 | + isa = PBXGroup; | |
| 262 | + children = ( | |
| 263 | + 7CD6752D2A271FE6008354C1 /* CNHexColor.swift */, | |
| 264 | + ); | |
| 265 | + name = Extensions; | |
| 266 | + path = Common; | |
| 267 | + sourceTree = "<group>"; | |
| 268 | + }; | |
| 269 | + 7CD6754D2A2840B9008354C1 /* Controller */ = { | |
| 270 | + isa = PBXGroup; | |
| 271 | + children = ( | |
| 272 | + 7CD6754E2A2840B9008354C1 /* CNMetaCodeHomePageController.swift */, | |
| 273 | + ); | |
| 274 | + name = Controller; | |
| 275 | + path = HomePage/Controller; | |
| 276 | + sourceTree = "<group>"; | |
| 277 | + }; | |
| 278 | + 7CD675502A29C036008354C1 /* Constant */ = { | |
| 279 | + isa = PBXGroup; | |
| 280 | + children = ( | |
| 281 | + 7CD675512A29C04B008354C1 /* CNLiveConstant.swift */, | |
| 282 | + ); | |
| 283 | + path = Constant; | |
| 284 | + sourceTree = "<group>"; | |
| 285 | + }; | |
| 186 | 286 | 818163AF2A25CFCC00579C86 = { |
| 187 | 287 | isa = PBXGroup; |
| 188 | 288 | children = ( |
| ... | ... | @@ -315,6 +415,7 @@ |
| 315 | 415 | TargetAttributes = { |
| 316 | 416 | 818163B72A25CFCC00579C86 = { |
| 317 | 417 | CreatedOnToolsVersion = 13.4.1; |
| 418 | + LastSwiftMigration = 1430; | |
| 318 | 419 | }; |
| 319 | 420 | 818163CD2A25CFCF00579C86 = { |
| 320 | 421 | CreatedOnToolsVersion = 13.4.1; |
| ... | ... | @@ -481,10 +582,24 @@ |
| 481 | 582 | isa = PBXSourcesBuildPhase; |
| 482 | 583 | buildActionMask = 2147483647; |
| 483 | 584 | files = ( |
| 585 | + 7CD675292A270F6A008354C1 /* WJColorChange.m in Sources */, | |
| 484 | 586 | 796398942A260C0100D045EB /* AppDelegate.swift in Sources */, |
| 485 | 587 | 7963989D2A260E6200D045EB /* CNLiveBaseViewController.swift in Sources */, |
| 486 | - 79A68C542A27307900DC3B43 /* CNLiveConfigMacro.swift in Sources */, | |
| 588 | + 7CD6752E2A271FE6008354C1 /* CNHexColor.swift in Sources */, | |
| 589 | + 7CD675482A274167008354C1 /* PGIndexBannerSubiew.m in Sources */, | |
| 590 | + 7CD6753D2A2740B0008354C1 /* CNMainView.swift in Sources */, | |
| 591 | + 7CD675522A29C04B008354C1 /* CNLiveConstant.swift in Sources */, | |
| 592 | + 7CD6753E2A2740B0008354C1 /* CNPayMoneyCodeView.swift in Sources */, | |
| 593 | + 7CD675402A2740B0008354C1 /* CNCollectMoneyCodeView.swift in Sources */, | |
| 594 | + 7CD6754F2A2840B9008354C1 /* CNMetaCodeHomePageController.swift in Sources */, | |
| 595 | + 7CD675472A274167008354C1 /* NewPagedFlowView.m in Sources */, | |
| 596 | + 79A68C4A2A26E6CE00DC3B43 /* Network.swift in Sources */, | |
| 487 | 597 | 796398932A260C0100D045EB /* ViewController.swift in Sources */, |
| 598 | + 7CD675422A2740F8008354C1 /* CNCustomIndexView.swift in Sources */, | |
| 599 | + 7CD6753F2A2740B0008354C1 /* CNTopCollectMoneyRemindView.swift in Sources */, | |
| 600 | + 7CD6753C2A2740B0008354C1 /* CNBottomPayMoneyRemindView.swift in Sources */, | |
| 601 | + 7CD675202A26F805008354C1 /* CNLiveConfig.swift in Sources */, | |
| 602 | + 79A68C4C2A26EA6000DC3B43 /* API.swift in Sources */, | |
| 488 | 603 | ); |
| 489 | 604 | runOnlyForDeploymentPostprocessing = 0; |
| 490 | 605 | }; |
| ... | ... | @@ -660,6 +775,7 @@ |
| 660 | 775 | buildSettings = { |
| 661 | 776 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; |
| 662 | 777 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; |
| 778 | + CLANG_ENABLE_MODULES = YES; | |
| 663 | 779 | CODE_SIGN_STYLE = Automatic; |
| 664 | 780 | CURRENT_PROJECT_VERSION = 1.0; |
| 665 | 781 | DEVELOPMENT_TEAM = 94X49GG3ZW; |
| ... | ... | @@ -680,6 +796,8 @@ |
| 680 | 796 | PRODUCT_BUNDLE_IDENTIFIER = com.cnlive.metaCode.debug; |
| 681 | 797 | PRODUCT_NAME = "$(TARGET_NAME)"; |
| 682 | 798 | SWIFT_EMIT_LOC_STRINGS = YES; |
| 799 | + SWIFT_OBJC_BRIDGING_HEADER = "metaCode/Classes/Vendors/metaCode-Bridging-Header.h"; | |
| 800 | + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; | |
| 683 | 801 | SWIFT_VERSION = 5.0; |
| 684 | 802 | TARGETED_DEVICE_FAMILY = "1,2"; |
| 685 | 803 | }; |
| ... | ... | @@ -691,6 +809,7 @@ |
| 691 | 809 | buildSettings = { |
| 692 | 810 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; |
| 693 | 811 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; |
| 812 | + CLANG_ENABLE_MODULES = YES; | |
| 694 | 813 | CODE_SIGN_STYLE = Automatic; |
| 695 | 814 | CURRENT_PROJECT_VERSION = 1.0; |
| 696 | 815 | DEVELOPMENT_TEAM = 94X49GG3ZW; |
| ... | ... | @@ -711,6 +830,7 @@ |
| 711 | 830 | PRODUCT_BUNDLE_IDENTIFIER = com.cnlive.metaCode.debug; |
| 712 | 831 | PRODUCT_NAME = "$(TARGET_NAME)"; |
| 713 | 832 | SWIFT_EMIT_LOC_STRINGS = YES; |
| 833 | + SWIFT_OBJC_BRIDGING_HEADER = "metaCode/Classes/Vendors/metaCode-Bridging-Header.h"; | |
| 714 | 834 | SWIFT_VERSION = 5.0; |
| 715 | 835 | TARGETED_DEVICE_FAMILY = "1,2"; |
| 716 | 836 | }; | ... | ... |
metaCode/Classes/Constant/CNLiveConstant.swift
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveConstant.swift | |
| 3 | +// metaCode | |
| 4 | +// | |
| 5 | +// Created by daojian on 2023/6/2. | |
| 6 | +// 全局常量 | |
| 7 | + | |
| 8 | +import Foundation | |
| 9 | + | |
| 10 | +///屏幕宽度 | |
| 11 | +let KSreenWidth = UIScreen.main.bounds.width | |
| 12 | +///屏幕高度 | |
| 13 | +let KSreenHeight = UIScreen.main.bounds.height | |
| 14 | + | |
| 15 | +///状态栏高度 | |
| 16 | +let KStatusBarHeight = UIApplication.shared.statusBarFrame.height; | |
| 17 | +///导航栏高度 | |
| 18 | +let KNavigationHeight = (KStatusBarHeight + 44) | |
| 19 | +///tabbar高度 | |
| 20 | +let KTabBarHeight = (KStatusBarHeight == 44 ? 83 : 49) | |
| 21 | + | |
| 22 | + | ... | ... |
metaCode/Classes/Main/HomePage/Controller/CNMetaCodeHomePageController.swift
0 → 100644
| 1 | +// | |
| 2 | +// CNMetaCodeHomePageController.swift | |
| 3 | +// metaCode | |
| 4 | +// | |
| 5 | +// Created by daojian on 2023/6/1. | |
| 6 | +// | |
| 7 | + | |
| 8 | +import Foundation | |
| 9 | +import UIKit | |
| 10 | +import YYCategories | |
| 11 | + | |
| 12 | +let Width: CGFloat = UIScreen.main.bounds.size.width | |
| 13 | +let Height: CGFloat = UIScreen.main.bounds.size.height | |
| 14 | + | |
| 15 | +class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDelegate, NewPagedFlowViewDataSource{ | |
| 16 | + | |
| 17 | + // MARK: - 懒加载 | |
| 18 | + ///数据源 | |
| 19 | + lazy var dataArray: NSMutableArray = { | |
| 20 | + | |
| 21 | + return NSMutableArray.init() | |
| 22 | + }() | |
| 23 | + | |
| 24 | + ///左右滑动分页view | |
| 25 | + lazy var pageFlowView: NewPagedFlowView = { | |
| 26 | + let pageFlowView = NewPagedFlowView.init(frame: CGRectMake(0, 0, Width, Height)); | |
| 27 | + | |
| 28 | + pageFlowView.delegate = self; | |
| 29 | + pageFlowView.dataSource = self; | |
| 30 | + pageFlowView.minimumPageAlpha = 0.1; | |
| 31 | + pageFlowView.isCarousel = false; | |
| 32 | + pageFlowView.orientation = .horizontal; | |
| 33 | + pageFlowView.leftRightMargin = 20; | |
| 34 | + pageFlowView.isOpenAutoScroll = false; | |
| 35 | + | |
| 36 | + //左右图片的距离顶部和底部的高度 | |
| 37 | + pageFlowView.topBottomMargin = 0; | |
| 38 | + | |
| 39 | + return pageFlowView | |
| 40 | + | |
| 41 | + }() | |
| 42 | + | |
| 43 | + //MARK: 生命周期方法 | |
| 44 | + override func viewDidLoad() { | |
| 45 | + super.viewDidLoad() | |
| 46 | + | |
| 47 | + | |
| 48 | + for i in (0..<2) { | |
| 49 | + self.dataArray.add("122") | |
| 50 | + } | |
| 51 | + | |
| 52 | + self.setupUI() | |
| 53 | + } | |
| 54 | + | |
| 55 | + // MARK: - 添加UI | |
| 56 | + func setupUI(){ | |
| 57 | + self.view.addSubview(self.pageFlowView) | |
| 58 | + self.pageFlowView.reloadData() | |
| 59 | + } | |
| 60 | + | |
| 61 | + // MARK: - NewPagedFlowView代理 | |
| 62 | + | |
| 63 | + func numberOfPages(in flowView: NewPagedFlowView!) -> Int { | |
| 64 | + self.dataArray.count | |
| 65 | + } | |
| 66 | + | |
| 67 | + func flowView(_ flowView: NewPagedFlowView!, cellForPageAt index: Int) -> PGIndexBannerSubiew! { | |
| 68 | + var bannerView:CNCustomIndexView? = flowView.dequeueReusableCell() as? CNCustomIndexView; | |
| 69 | + | |
| 70 | + if (bannerView == nil) { | |
| 71 | + bannerView = CNCustomIndexView.init(frame: CGRectMake(0, 0, Width-50, Height)); | |
| 72 | + bannerView?.tag = index + 100; | |
| 73 | + bannerView?.layer.cornerRadius = 4; | |
| 74 | + bannerView?.layer.masksToBounds = false; | |
| 75 | + } | |
| 76 | + bannerView?.superScrollView = flowView.scrollView; | |
| 77 | + bannerView?.associatedVCView = self.view; | |
| 78 | + return bannerView; | |
| 79 | + } | |
| 80 | + | |
| 81 | + func sizeForPage(in flowView: NewPagedFlowView!) -> CGSize { | |
| 82 | + return CGSize(width: Width-50, height: Height) | |
| 83 | + } | |
| 84 | + | |
| 85 | +} | ... | ... |
metaCode/Classes/Main/HomePage/View/CNBottomPayMoneyRemindView.swift
0 → 100644
| 1 | +// | |
| 2 | +// CNBottomPayMoneyRemindView.swift | |
| 3 | +// metaCode | |
| 4 | +// | |
| 5 | +// Created by daojian on 2023/5/31. | |
| 6 | +// | |
| 7 | + | |
| 8 | +import Foundation | |
| 9 | +import YYCategories | |
| 10 | + | |
| 11 | +/// 底部付钱上拉显示提醒View | |
| 12 | +class CNBottomPayMoneyRemindView:UIView{ | |
| 13 | + | |
| 14 | + override init(frame: CGRect) { | |
| 15 | + super.init(frame: frame) | |
| 16 | + self.initUI() | |
| 17 | + } | |
| 18 | + | |
| 19 | + required init?(coder: NSCoder) { | |
| 20 | + fatalError("init(coder:) has not been implemented") | |
| 21 | + } | |
| 22 | + | |
| 23 | + func initUI(){ | |
| 24 | + | |
| 25 | + let W = UIScreen.main.bounds.width - 100 | |
| 26 | + let bottomCircle = UIBezierPath.init(arcCenter: CGPoint(x: W/2, y: W/2), radius: W/2, startAngle: 0, endAngle: .pi, clockwise: false) | |
| 27 | + | |
| 28 | + let bottomShapeLayer = CAShapeLayer() | |
| 29 | + bottomShapeLayer.path = bottomCircle.cgPath | |
| 30 | + bottomShapeLayer.fillColor = UIColor("#FCE0E0")?.cgColor | |
| 31 | + self.layer.addSublayer(bottomShapeLayer) | |
| 32 | + | |
| 33 | + let btn = UIButton(type: .custom) | |
| 34 | + btn.frame = CGRect(x: (self.width - 50)/2, y: 20, width: 50, height: 50) | |
| 35 | + btn.setTitle("付钱", for: .normal) | |
| 36 | + btn.setTitleColor(UIColor.red, for: .normal) | |
| 37 | + btn.titleLabel?.font = UIFont(name: "KohinoorTelugu-Regular", size: 17) | |
| 38 | + btn.isUserInteractionEnabled = false | |
| 39 | + | |
| 40 | + self.addSubview(btn) | |
| 41 | + | |
| 42 | + } | |
| 43 | + | |
| 44 | + | |
| 45 | +} | ... | ... |
metaCode/Classes/Main/HomePage/View/CNCollectMoneyCodeView.swift
0 → 100644
| 1 | +// | |
| 2 | +// CNCollectMoneyCodeView.swift | |
| 3 | +// metaCode | |
| 4 | +// | |
| 5 | +// Created by daojian on 2023/5/30. | |
| 6 | +// | |
| 7 | + | |
| 8 | +import Foundation | |
| 9 | +import UIKit | |
| 10 | +import YYCategories | |
| 11 | + | |
| 12 | +///收钱码View | |
| 13 | +class CNCollectMoneyCodeView:UIView{ | |
| 14 | + | |
| 15 | + ///懒加载 | |
| 16 | + lazy var contentView:UIView = { | |
| 17 | + | |
| 18 | + let contentView = UIView.init(frame: CGRect(x: 0, y: 0, width: self.width, height: self.height-150)) | |
| 19 | + contentView.backgroundColor = UIColor.white | |
| 20 | + | |
| 21 | + let path:UIBezierPath = UIBezierPath.init(roundedRect: contentView.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize.init(width: 20, height: 20)) | |
| 22 | + | |
| 23 | + let maskLayer:CAShapeLayer = CAShapeLayer() | |
| 24 | + maskLayer.frame = contentView.bounds | |
| 25 | + maskLayer.path = path.cgPath | |
| 26 | + contentView.layer.mask = maskLayer | |
| 27 | + | |
| 28 | + let imageView = UIImageView(frame: CGRect(x: 10, y: 20, width: contentView.width - 20, height: contentView.height - 40)) | |
| 29 | + imageView.image = UIImage(named: "homePage_collectMoneyImage") | |
| 30 | + contentView.addSubview(imageView) | |
| 31 | + | |
| 32 | + return contentView | |
| 33 | + }() | |
| 34 | + | |
| 35 | + lazy var topView:UIView = { | |
| 36 | + | |
| 37 | + let tempTopView = UIView(frame: CGRect(x:0, y:20, width: self.width - 50, height: 70)) | |
| 38 | + | |
| 39 | + return tempTopView | |
| 40 | + }() | |
| 41 | + | |
| 42 | + override init(frame: CGRect) { | |
| 43 | + super.init(frame: frame) | |
| 44 | + self.initUI() | |
| 45 | + } | |
| 46 | + | |
| 47 | + required init?(coder: NSCoder) { | |
| 48 | + fatalError("init(coder:) has not been implemented") | |
| 49 | + } | |
| 50 | + | |
| 51 | + | |
| 52 | + ///初始化UI | |
| 53 | + func initUI(){ | |
| 54 | + self.addSubview(self.contentView) | |
| 55 | + self.addSubview(self.topView) | |
| 56 | + } | |
| 57 | + | |
| 58 | +} | ... | ... |
metaCode/Classes/Main/HomePage/View/CNCustomIndexView.swift
0 → 100644
| 1 | +// | |
| 2 | +// CNCustomIndexView.swift | |
| 3 | +// metaCode | |
| 4 | +// | |
| 5 | +// Created by daojian on 2023/5/31. | |
| 6 | +// | |
| 7 | + | |
| 8 | +import Foundation | |
| 9 | + | |
| 10 | +///关联的控制器的view | |
| 11 | +//@property (nonatomic, weak)UIView *associatedVCView | |
| 12 | +// | |
| 13 | +/////父视图ScrollView | |
| 14 | +//@property (nonatomic, weak)UIScrollView *superScrollView | |
| 15 | +/////自己的底部ScrollView,用来装载 | |
| 16 | +//@property (nonatomic, strong)UIScrollView *baseScrollView | |
| 17 | +// | |
| 18 | +//@property (nonatomic, strong)CNMainView *mainView | |
| 19 | +//@property (nonatomic, strong)CNCollectMoneyCodeView *collectMoneyCodeView | |
| 20 | +//@property (nonatomic, strong)CNPayMoneyCodeView *payMoneyCodeView | |
| 21 | + | |
| 22 | +class CNCustomIndexView:PGIndexBannerSubiew, UIScrollViewDelegate, WJColorChangeDelegate{ | |
| 23 | + | |
| 24 | + var colorChange: WJColorChange! | |
| 25 | + | |
| 26 | + ///关联的控制器的view | |
| 27 | + weak var associatedVCView:UIView? | |
| 28 | + { | |
| 29 | + | |
| 30 | + willSet | |
| 31 | + { | |
| 32 | + print("Will set an new value \(String(describing: newValue)) to age") | |
| 33 | + } | |
| 34 | + //我们需要在age属性发生变化后,更新一下nickName这个属性 | |
| 35 | + didSet | |
| 36 | + { | |
| 37 | + self.addColorManager() | |
| 38 | + } | |
| 39 | + } | |
| 40 | + ///父视图ScrollView | |
| 41 | + weak var superScrollView:UIScrollView? | |
| 42 | + | |
| 43 | + // MARK: - 懒加载 | |
| 44 | + | |
| 45 | + ///颜色数据 | |
| 46 | + lazy var colorDataArr: NSMutableArray = { | |
| 47 | + let colorDataArr = NSMutableArray(array: NSArray(objects: UIColor.black,UIColor.white,UIColor.red)) | |
| 48 | + | |
| 49 | + return colorDataArr | |
| 50 | + }() | |
| 51 | + | |
| 52 | + ///自己的ScrollView,用来装载子视图 | |
| 53 | + lazy var baseScrollView:UIScrollView = { | |
| 54 | + let baseScrollView : UIScrollView = UIScrollView.init(frame: CGRect(x: 0, y: 0, width: self.width, height: self.height)) | |
| 55 | + baseScrollView.contentSize = CGSizeMake(self.frame.size.width, self.frame.size.height*3) | |
| 56 | + baseScrollView.delegate = self | |
| 57 | + baseScrollView.bounces = false | |
| 58 | + baseScrollView.isPagingEnabled = true | |
| 59 | + baseScrollView.clipsToBounds = false | |
| 60 | + baseScrollView.showsHorizontalScrollIndicator = false | |
| 61 | + baseScrollView.showsVerticalScrollIndicator = false | |
| 62 | + if #available(iOS 11.0, *) { | |
| 63 | + //系统版本高于11.0 | |
| 64 | + baseScrollView.contentInsetAdjustmentBehavior = .never | |
| 65 | + | |
| 66 | + } else { | |
| 67 | + //系统版本低于11.0 | |
| 68 | + baseScrollView.automaticallyAdjustsScrollIndicatorInsets = false | |
| 69 | + } | |
| 70 | + return baseScrollView | |
| 71 | + | |
| 72 | + }() | |
| 73 | + | |
| 74 | + ///中间主界面 | |
| 75 | + lazy var mainView:CNMainView = { | |
| 76 | + let W = self.width | |
| 77 | + let H = W*1.5 | |
| 78 | + let mainView = CNMainView.init(frame: CGRectMake(0, self.frame.size.height + (self.frame.size.height-H)/2,W, H)) | |
| 79 | + return mainView | |
| 80 | + }() | |
| 81 | + | |
| 82 | + ///收钱view | |
| 83 | + lazy var collectMoneyCodeView: CNCollectMoneyCodeView = { | |
| 84 | + let collectionView = CNCollectMoneyCodeView.init(frame: CGRectMake(-25, 0, self.frame.size.width + 50, self.frame.size.height)) | |
| 85 | + return collectionView | |
| 86 | + }() | |
| 87 | + | |
| 88 | + ///付钱view | |
| 89 | + lazy var payMoneyCodeView : CNPayMoneyCodeView = { | |
| 90 | + let payMoneyCodeView = CNPayMoneyCodeView(frame: CGRectMake(-25, self.frame.size.height*2 + 150,self.frame.size.width+50, self.frame.size.height - 150)) | |
| 91 | + | |
| 92 | + return payMoneyCodeView | |
| 93 | + }() | |
| 94 | + | |
| 95 | + ///底部付钱提前view | |
| 96 | + lazy var bottomPayMoneyRemindView: CNBottomPayMoneyRemindView = { | |
| 97 | + let W: CGFloat = UIScreen.main.bounds.width-100 | |
| 98 | + let bottomView = CNBottomPayMoneyRemindView.init(frame: CGRectMake(25, self.baseScrollView.height*2, W,W/2)) | |
| 99 | + bottomView.backgroundColor = UIColor.clear | |
| 100 | + return bottomView | |
| 101 | + }() | |
| 102 | + /// 顶部收钱提前view | |
| 103 | + lazy var topCollectMoneyRemindView:CNTopCollectMoneyRemindView = { | |
| 104 | + let W: CGFloat = UIScreen.main.bounds.width-100 | |
| 105 | + let topView = CNTopCollectMoneyRemindView.init(frame: CGRectMake(25, self.baseScrollView.height-W/2, W,W/2)) | |
| 106 | + topView.backgroundColor = .clear | |
| 107 | + return topView | |
| 108 | + }() | |
| 109 | + | |
| 110 | + // MARK: - 初始化方法 | |
| 111 | + override init(frame: CGRect) { | |
| 112 | + super.init(frame: frame) | |
| 113 | + self.initUI() | |
| 114 | + } | |
| 115 | + | |
| 116 | + required init?(coder: NSCoder) { | |
| 117 | + fatalError("init(coder:) has not been implemented") | |
| 118 | + } | |
| 119 | + | |
| 120 | + // MARK: - 添加UI | |
| 121 | + func initUI(){ | |
| 122 | + self.addSubview(self.baseScrollView) | |
| 123 | + self.baseScrollView.addSubview(self.collectMoneyCodeView) | |
| 124 | + | |
| 125 | + self.baseScrollView.addSubview(self.mainView) | |
| 126 | + self.baseScrollView.addSubview(self.payMoneyCodeView) | |
| 127 | + self.baseScrollView.addSubview(self.bottomPayMoneyRemindView) | |
| 128 | + self.baseScrollView.addSubview(self.topCollectMoneyRemindView) | |
| 129 | + | |
| 130 | + //默认偏移到中间 | |
| 131 | + self.baseScrollView.setContentOffset(CGPointMake(0, self.frame.size.height), animated: false) | |
| 132 | + } | |
| 133 | + | |
| 134 | +// // MARK: - 手势 | |
| 135 | +// func addCustomGestureRecognizer(){ | |
| 136 | +// let singleTap: UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(singleCellTapAction)) | |
| 137 | +// | |
| 138 | +// self.addGestureRecognizer(singleTap) | |
| 139 | +// } | |
| 140 | + | |
| 141 | + // MARK: - 设置颜色值跟随ScrollView滑动变化 | |
| 142 | + func addColorManager() | |
| 143 | + { | |
| 144 | + print(self.colorDataArr) | |
| 145 | + let colorChange:WJColorChange = WJColorChange.init(type:SingleColor) | |
| 146 | + colorChange.delegate = self | |
| 147 | + colorChange.offset = 100 | |
| 148 | + colorChange.settingScrollView(self.baseScrollView, colorArray: self.colorDataArr as! [UIColor], needChangeColorView: self.associatedVCView) | |
| 149 | + | |
| 150 | + self.colorChange = colorChange | |
| 151 | + } | |
| 152 | + | |
| 153 | + // MARK: - WJColorChange代理 | |
| 154 | + ///WJColorChange 代理方法 滚动时候回调 传出当前的滚动视图 | |
| 155 | + func wjColorScrollViewScroll(_ scrollView: UIScrollView!) { | |
| 156 | + | |
| 157 | + let tag: NSInteger = self.tag | |
| 158 | + let defaultOffset: CGFloat = self.frame.size.height | |
| 159 | + | |
| 160 | + let currentOffset: CGFloat = scrollView.contentOffset.y | |
| 161 | + | |
| 162 | + /**隐藏左右view*/ | |
| 163 | + let fabsOffset: CGFloat = fabs(defaultOffset - currentOffset) | |
| 164 | + | |
| 165 | + let leftView:UIView? = self.superScrollView?.viewWithTag(tag-1) | |
| 166 | + let rightView:UIView? = self.superScrollView?.viewWithTag(tag+1) | |
| 167 | + if fabsOffset > 70 { | |
| 168 | + leftView?.alpha = 0 | |
| 169 | + rightView?.alpha = 0 | |
| 170 | + } | |
| 171 | + else{ | |
| 172 | + leftView?.alpha = (70-fabsOffset)/70.00 | |
| 173 | + rightView?.alpha = (70-fabsOffset)/70.00 | |
| 174 | + } | |
| 175 | + | |
| 176 | + //上滑滑动到临近值,让bottomPayMoneyRemindView位置一直停留在底部,并慢慢消失 | |
| 177 | + let bottomPayMoneyRemindViewMaxOffset: CGFloat = self.baseScrollView.height+self.bottomPayMoneyRemindView.height | |
| 178 | + if (currentOffset > bottomPayMoneyRemindViewMaxOffset) { | |
| 179 | + /**让bottomPayMoneyRemindView位置一直停留在底部*/ | |
| 180 | + self.bottomPayMoneyRemindView.top = currentOffset+self.baseScrollView.height-self.bottomPayMoneyRemindView.height | |
| 181 | + | |
| 182 | + /**渐渐隐藏bottomPayMoneyRemindView,缓冲距离为40*/ | |
| 183 | + self.bottomPayMoneyRemindView.alpha = (40-(currentOffset - bottomPayMoneyRemindViewMaxOffset))/40.00 | |
| 184 | + | |
| 185 | + //让系统及时更新bottomPayMoneyRemindView | |
| 186 | +// self.bottomPayMoneyRemindView.setNeedsLayout() | |
| 187 | +// self.bottomPayMoneyRemindView.layoutIfNeeded() | |
| 188 | + } | |
| 189 | + | |
| 190 | + //下滑滑动到临近值,让topCollectMoneyRemindView位置一直停留在底部,并慢慢消失 | |
| 191 | + let topCollectMoneyRemindViewMinOffset: CGFloat = self.baseScrollView.height-self.topCollectMoneyRemindView.height | |
| 192 | + if (currentOffset < topCollectMoneyRemindViewMinOffset) { | |
| 193 | + /**让topCollectMoneyRemindView位置一直停留在底部*/ | |
| 194 | + self.topCollectMoneyRemindView.bottom = currentOffset+self.topCollectMoneyRemindView.height | |
| 195 | + | |
| 196 | + /**渐渐隐藏topCollectMoneyRemindView,缓冲距离为40*/ | |
| 197 | + print("currentOffset =", topCollectMoneyRemindViewMinOffset - currentOffset) | |
| 198 | + | |
| 199 | + self.topCollectMoneyRemindView.alpha = (40-(topCollectMoneyRemindViewMinOffset - currentOffset))/40.00 | |
| 200 | + | |
| 201 | + //让系统及时更新topCollectMoneyRemindView | |
| 202 | +// self.topCollectMoneyRemindView.setNeedsLayout() | |
| 203 | +// self.topCollectMoneyRemindView.layoutIfNeeded() | |
| 204 | + } | |
| 205 | + | |
| 206 | + | |
| 207 | + /**控制缩放范围在一定范围*/ | |
| 208 | + let mainViewOffset:CGFloat = abs(currentOffset - self.baseScrollView.height) | |
| 209 | + if (mainViewOffset < 100) { | |
| 210 | + var scale: CGFloat = 1.0 | |
| 211 | + | |
| 212 | + if (currentOffset < self.baseScrollView.height) { | |
| 213 | + //下滑时,计算scale方法 | |
| 214 | + scale = currentOffset/self.baseScrollView.height | |
| 215 | + } | |
| 216 | + else { | |
| 217 | + //上滑时,计算scale方法 | |
| 218 | + scale = self.baseScrollView.height/currentOffset | |
| 219 | + } | |
| 220 | + | |
| 221 | + self.mainView.scaledView(scale: scale) | |
| 222 | + } | |
| 223 | + | |
| 224 | + } | |
| 225 | + | |
| 226 | + ///WJColorChange 代理方法 滚动结束时候回调 | |
| 227 | + func wjColorEndScroll(_ scrollView: UIScrollView!) { | |
| 228 | + | |
| 229 | + | |
| 230 | + let defaultOffset: CGFloat = self.frame.size.height | |
| 231 | + | |
| 232 | + let currentOffset: CGFloat = scrollView.contentOffset.y | |
| 233 | + | |
| 234 | + if ((currentOffset < (defaultOffset + 1)) && | |
| 235 | + (currentOffset > (defaultOffset - 1)) | |
| 236 | + ) { | |
| 237 | + self.superScrollView?.isScrollEnabled = true | |
| 238 | + } | |
| 239 | + else{ | |
| 240 | + self.superScrollView?.isScrollEnabled = false | |
| 241 | + } | |
| 242 | + | |
| 243 | + } | |
| 244 | + | |
| 245 | +} | |
| 246 | + | ... | ... |
metaCode/Classes/Main/HomePage/View/CNMainView.swift
0 → 100644
| 1 | +// | |
| 2 | +// CNMainView.swift | |
| 3 | +// metaCode | |
| 4 | +// | |
| 5 | +// Created by daojian on 2023/5/31. | |
| 6 | +// | |
| 7 | + | |
| 8 | +import Foundation | |
| 9 | +import YYCategories | |
| 10 | + | |
| 11 | +typealias closureBlock = ()->Void; | |
| 12 | + | |
| 13 | +///正面View | |
| 14 | +class CNFrontMainView : UIView{ | |
| 15 | + ///点击反转事件 | |
| 16 | + var tapTransformAciton:closureBlock? | |
| 17 | + | |
| 18 | + override init(frame: CGRect) { | |
| 19 | + super.init(frame: frame) | |
| 20 | + self.initUI() | |
| 21 | + let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapAction)) | |
| 22 | + self.addGestureRecognizer(tap) | |
| 23 | + } | |
| 24 | + | |
| 25 | + required init?(coder: NSCoder) { | |
| 26 | + fatalError("init(coder:) has not been implemented") | |
| 27 | + } | |
| 28 | + | |
| 29 | + lazy var imageView:UIImageView = { | |
| 30 | + | |
| 31 | + let tempImageView:UIImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: self.width, height: self.width * 0.7)) | |
| 32 | + tempImageView.image = UIImage(named: "homePage_zhongguorenming_bank") | |
| 33 | + | |
| 34 | + let path : UIBezierPath = UIBezierPath.init(roundedRect: tempImageView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 20, height: 20)) | |
| 35 | + | |
| 36 | + let maskLayer = CAShapeLayer() | |
| 37 | + maskLayer.frame = tempImageView.bounds | |
| 38 | + maskLayer.path = path.cgPath | |
| 39 | + tempImageView.layer.mask = maskLayer | |
| 40 | + | |
| 41 | + return tempImageView | |
| 42 | + }() | |
| 43 | + | |
| 44 | + lazy var contentView : UIView = { | |
| 45 | + | |
| 46 | + let contentView = UIView.init(frame: CGRect(x: 0, y: self.imageView.bottom - 20, width: self.width, height: self.height - self.imageView.bottom + 20)) | |
| 47 | + contentView.backgroundColor = UIColor.white | |
| 48 | + contentView.clipsToBounds = true | |
| 49 | + contentView.layer.cornerRadius = 20 | |
| 50 | + | |
| 51 | + let imageView = UIImageView.init(frame: CGRect(x: 10, y: 10, width: contentView.width - 20, height: contentView.height - 20)) | |
| 52 | + imageView.image = UIImage.init(named: "homePage_mainView_front"); | |
| 53 | + contentView.addSubview(imageView) | |
| 54 | + | |
| 55 | + return contentView | |
| 56 | + | |
| 57 | + }() | |
| 58 | + | |
| 59 | + func initUI() | |
| 60 | + { | |
| 61 | + self.addSubview(self.imageView) | |
| 62 | + self.addSubview(self.contentView) | |
| 63 | + } | |
| 64 | + | |
| 65 | + @objc func tapAction(){ | |
| 66 | + if (self.tapTransformAciton != nil){ | |
| 67 | + self.tapTransformAciton | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 71 | +} | |
| 72 | + | |
| 73 | +///反面View | |
| 74 | +class CNBackMainView : UIView{ | |
| 75 | + ///点击反转事件 | |
| 76 | + var tapTransformAciton:closureBlock? | |
| 77 | + | |
| 78 | + override init(frame: CGRect) { | |
| 79 | + super.init(frame: frame) | |
| 80 | + self.initUI() | |
| 81 | + let tap:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapAction)) | |
| 82 | + self.addGestureRecognizer(tap) | |
| 83 | + } | |
| 84 | + | |
| 85 | + required init?(coder: NSCoder) { | |
| 86 | + fatalError("init(coder:) has not been implemented") | |
| 87 | + } | |
| 88 | + | |
| 89 | + lazy var imageView:UIImageView = { | |
| 90 | + | |
| 91 | + let tempImageView:UIImageView = UIImageView(frame: CGRect(x: 10, y: 10, width: self.width-20, height: self.height - 20)) | |
| 92 | + tempImageView.image = UIImage(named: "homePage_backViewImage") | |
| 93 | + | |
| 94 | + return tempImageView | |
| 95 | + }() | |
| 96 | + | |
| 97 | + lazy var contentView : UIView = { | |
| 98 | + | |
| 99 | + let contentView = UIView.init(frame: CGRect(x: 0, y: self.imageView.bottom - 20, width: self.width, height: self.height-self.imageView.bottom + 20)) | |
| 100 | + contentView.backgroundColor = UIColor.white | |
| 101 | + contentView.clipsToBounds = true | |
| 102 | + contentView.layer.cornerRadius = 20 | |
| 103 | + | |
| 104 | + return contentView | |
| 105 | + | |
| 106 | + }() | |
| 107 | + | |
| 108 | + func initUI() | |
| 109 | + { | |
| 110 | + self.addSubview(self.imageView) | |
| 111 | + self.addSubview(self.contentView) | |
| 112 | + } | |
| 113 | + | |
| 114 | + @objc func tapAction(){ | |
| 115 | + if (self.tapTransformAciton != nil){ | |
| 116 | + self.tapTransformAciton | |
| 117 | + } | |
| 118 | + } | |
| 119 | +} | |
| 120 | + | |
| 121 | +///旋转动画时间 | |
| 122 | +let KTransformAnimationTime:CGFloat = 0.75; | |
| 123 | + | |
| 124 | +///中间主VIew | |
| 125 | +class CNMainView : UIView{ | |
| 126 | + | |
| 127 | + override init(frame: CGRect) { | |
| 128 | + super.init(frame: frame) | |
| 129 | + self.initUI() | |
| 130 | + } | |
| 131 | + | |
| 132 | + required init?(coder: NSCoder) { | |
| 133 | + fatalError("init(coder:) has not been implemented") | |
| 134 | + } | |
| 135 | + | |
| 136 | + lazy var frontView:CNFrontMainView = { | |
| 137 | +// _frontView = [[CNFrontMainView alloc] initWithFrame:self.bounds]; | |
| 138 | +// __weak CNMainView *weakSelf = self; | |
| 139 | +// _frontView.tapTransformAciton = ^{ | |
| 140 | +// [weakSelf transformToBacnkView]; | |
| 141 | +// }; | |
| 142 | + let frontView = CNFrontMainView.init(frame: self.bounds) | |
| 143 | + frontView.tapTransformAciton = { | |
| 144 | + | |
| 145 | + print("点击了") | |
| 146 | + } | |
| 147 | + return frontView | |
| 148 | + }() | |
| 149 | + | |
| 150 | + lazy var backView:CNBackMainView = { | |
| 151 | + let backView = CNBackMainView.init(frame: self.bounds) | |
| 152 | + backView.tapTransformAciton = { | |
| 153 | + | |
| 154 | + print("点击了") | |
| 155 | + } | |
| 156 | + return backView | |
| 157 | + }() | |
| 158 | + | |
| 159 | + func initUI() | |
| 160 | + { | |
| 161 | + self.addSubview(self.frontView) | |
| 162 | + self.addSubview(self.backView) | |
| 163 | + self.backView.isHidden = true; | |
| 164 | + | |
| 165 | + self.layer.cornerRadius = 20; | |
| 166 | + self.layer.shadowOpacity = 1; | |
| 167 | + self.layer.shadowColor = UIColor("#eeeeee")?.cgColor | |
| 168 | + self.layer.shadowOffset = CGSize(width: 10, height: 10) | |
| 169 | + self.layer.shadowRadius = 10; | |
| 170 | + | |
| 171 | + } | |
| 172 | + | |
| 173 | + /***********事件*****************/ | |
| 174 | + ///旋转到反面 | |
| 175 | + func transformToBacnkView() | |
| 176 | + { | |
| 177 | + //旋转动画 | |
| 178 | + UIView.animate(withDuration: KTransformAnimationTime) { | |
| 179 | + self.layer.transform = CATransform3DMakeRotation(.pi, 0, 1, 0); | |
| 180 | + } | |
| 181 | + | |
| 182 | + //让背面也旋转180度 | |
| 183 | + self.backView.layer.transform = CATransform3DMakeRotation(.pi, 0, 1, 0); | |
| 184 | + | |
| 185 | + //在中间时刻进行正反面view的隐藏显示处理 | |
| 186 | + let deadline = DispatchTime.now() - DispatchTimeInterval.milliseconds(50) + DispatchTimeInterval.milliseconds(Int (KTransformAnimationTime*1000/2)) | |
| 187 | + | |
| 188 | + DispatchQueue.main.asyncAfter(deadline: deadline, execute: DispatchWorkItem(block: { | |
| 189 | + UIView.animate(withDuration: 0.05) { | |
| 190 | + self.frontView.isHidden = true; | |
| 191 | + self.backView.isHidden = false; | |
| 192 | + } | |
| 193 | + })) | |
| 194 | + | |
| 195 | + | |
| 196 | + } | |
| 197 | + ///旋转到正面 | |
| 198 | + func transformToFrontView() | |
| 199 | + { | |
| 200 | + //旋转动画 | |
| 201 | + UIView.animate(withDuration: KTransformAnimationTime) { | |
| 202 | + self.layer.transform = CATransform3DMakeRotation(0, 0, 1, 0); | |
| 203 | + | |
| 204 | + } completion: { _ in | |
| 205 | + //背面恢复旋转 | |
| 206 | + self.backView.layer.transform = CATransform3DMakeRotation(0, 0, 1, 0); | |
| 207 | + } | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + //在中间时刻进行正反面view的隐藏显示处理 | |
| 212 | + let deadline = DispatchTime.now() - DispatchTimeInterval.milliseconds(50) + DispatchTimeInterval.milliseconds(Int (KTransformAnimationTime*1000/2)) | |
| 213 | + | |
| 214 | + DispatchQueue.main.asyncAfter(deadline: deadline, execute: DispatchWorkItem(block: { | |
| 215 | + UIView.animate(withDuration: 0.05) { | |
| 216 | + self.frontView.isHidden = false; | |
| 217 | + self.backView.isHidden = true; | |
| 218 | + } | |
| 219 | + })) | |
| 220 | + | |
| 221 | + } | |
| 222 | + | |
| 223 | + ///缩放 | |
| 224 | + open func scaledView(scale:CGFloat) | |
| 225 | + { | |
| 226 | + self.frontView.imageView.transform = CGAffineTransformMakeScale(scale, scale); | |
| 227 | + } | |
| 228 | +} | |
| 229 | + | ... | ... |
metaCode/Classes/Main/HomePage/View/CNPayMoneyCodeView.swift
0 → 100644
| 1 | +// | |
| 2 | +// CNPayMoneyCodeView.swift | |
| 3 | +// metaCode | |
| 4 | +// | |
| 5 | +// Created by daojian on 2023/5/31. | |
| 6 | +// | |
| 7 | + | |
| 8 | +import Foundation | |
| 9 | +import YYCategories | |
| 10 | + | |
| 11 | +///付钱码view | |
| 12 | +class CNPayMoneyCodeView:UIView{ | |
| 13 | + override init(frame: CGRect) { | |
| 14 | + super.init(frame: frame) | |
| 15 | + self.initUI() | |
| 16 | + | |
| 17 | + } | |
| 18 | + | |
| 19 | + required init?(coder: NSCoder) { | |
| 20 | + fatalError("init(coder:) has not been implemented") | |
| 21 | + } | |
| 22 | + | |
| 23 | + func initUI() | |
| 24 | + { | |
| 25 | + self.backgroundColor = UIColor.white; | |
| 26 | + self.clipsToBounds = true; | |
| 27 | + self.layer.cornerRadius = 20; | |
| 28 | + | |
| 29 | + let imageview : UIImageView = UIImageView.init(frame: CGRect(x: 20, y: 10, width: self.width - 40, height: self.height - 20)) | |
| 30 | + imageview.image = UIImage(named: "homePage_payMoneyImage") | |
| 31 | + | |
| 32 | + self.addSubview(imageview) | |
| 33 | + | |
| 34 | + } | |
| 35 | + | |
| 36 | +} | ... | ... |
metaCode/Classes/Main/HomePage/View/CNTopCollectMoneyRemindView.swift
0 → 100644
| 1 | +// | |
| 2 | +// CNTopCollectMoneyRemindView.swift | |
| 3 | +// metaCode | |
| 4 | +// | |
| 5 | +// Created by daojian on 2023/5/31. | |
| 6 | +// | |
| 7 | + | |
| 8 | +import Foundation | |
| 9 | +import YYCategories | |
| 10 | + | |
| 11 | +///收钱下拉显示提醒View | |
| 12 | +class CNTopCollectMoneyRemindView : UIView{ | |
| 13 | + override init(frame: CGRect) { | |
| 14 | + super.init(frame: frame) | |
| 15 | + self.initUI() | |
| 16 | + } | |
| 17 | + | |
| 18 | + required init?(coder: NSCoder) { | |
| 19 | + fatalError("init(coder:) has not been implemented") | |
| 20 | + } | |
| 21 | + | |
| 22 | + func initUI(){ | |
| 23 | +// CGFloat W = kScreenWidth - 100; | |
| 24 | +// UIBezierPath *bottomCircle = [UIBezierPath bezierPathWithArcCenter:CGPointMake(W/2, 0) radius:W/2 startAngle:0 endAngle:M_PI clockwise:YES]; | |
| 25 | +// CAShapeLayer *bottomShapeLayer = [[CAShapeLayer alloc] init]; | |
| 26 | +// bottomShapeLayer.path = bottomCircle.CGPath; | |
| 27 | +// bottomShapeLayer.fillColor = CNLiveColorWithHexString(@"#F5F5F5").CGColor; | |
| 28 | +// | |
| 29 | +// [self.layer addSublayer:bottomShapeLayer]; | |
| 30 | +// | |
| 31 | +// UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom]; | |
| 32 | +// btn.frame = CGRectMake((self.width - 50)/2, self.height-70, 50, 50); | |
| 33 | +// [btn setTitle:@"收钱" forState:UIControlStateNormal]; | |
| 34 | +// [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; | |
| 35 | +// btn.titleLabel.font = [UIFont systemFontOfSize:17]; | |
| 36 | +// btn.userInteractionEnabled = NO; | |
| 37 | + | |
| 38 | + let W = UIScreen.main.bounds.width - 100 | |
| 39 | + let bottomCircle = UIBezierPath.init(arcCenter: CGPoint(x: W/2, y: 0), radius: W/2, startAngle: 0, endAngle: .pi, clockwise: true) | |
| 40 | + | |
| 41 | + let bottomShapeLayer = CAShapeLayer() | |
| 42 | + bottomShapeLayer.path = bottomCircle.cgPath | |
| 43 | + bottomShapeLayer.fillColor = UIColor("#FCE0E0")?.cgColor | |
| 44 | + self.layer.addSublayer(bottomShapeLayer) | |
| 45 | + | |
| 46 | + let btn = UIButton(type: .custom) | |
| 47 | + btn.frame = CGRect(x: (self.width - 50)/2, y: self.height-70, width: 50, height: 50) | |
| 48 | + btn.setTitle("收钱", for: .normal) | |
| 49 | + btn.setTitleColor(UIColor.red, for: .normal) | |
| 50 | + btn.titleLabel?.font = UIFont(name: "KohinoorTelugu-Regular", size: 17) | |
| 51 | + btn.isUserInteractionEnabled = false | |
| 52 | + | |
| 53 | + self.addSubview(btn) | |
| 54 | + } | |
| 55 | +} | |
| 56 | + | ... | ... |
metaCode/Classes/Other/AppDelegate.swift
| ... | ... | @@ -19,7 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { |
| 19 | 19 | // Override point for customization after application launch. |
| 20 | 20 | window = UIWindow.init(frame: UIScreen.main.bounds) |
| 21 | 21 | window?.backgroundColor = UIColor.white |
| 22 | - window?.rootViewController = ViewController.init() | |
| 22 | + window?.rootViewController = CNMetaCodeHomePageController.init() | |
| 23 | 23 | window?.makeKeyAndVisible() |
| 24 | 24 | |
| 25 | 25 | ... | ... |
metaCode/Classes/Other/ViewController.swift
| ... | ... | @@ -13,6 +13,7 @@ class ViewController: UIViewController { |
| 13 | 13 | override func viewDidLoad() { |
| 14 | 14 | super.viewDidLoad() |
| 15 | 15 | // Do any additional setup after loading the view. |
| 16 | + | |
| 16 | 17 | self.view.backgroundColor = .gray |
| 17 | 18 | |
| 18 | 19 | |
| ... | ... | @@ -55,6 +56,7 @@ class ViewController: UIViewController { |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | 58 | |
| 59 | + | |
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | ... | ... |
metaCode/Classes/Vendors/NewPagedFlowView.h
0 → 100755
| 1 | +// | |
| 2 | +// NewPagedFlowView.h | |
| 3 | +// dianshang | |
| 4 | +// | |
| 5 | +// Created by sskh on 16/7/13. | |
| 6 | +// Copyright © 2016年 Mars. All rights reserved. | |
| 7 | +// Designed By PageGuo, | |
| 8 | +// QQ:799573715 | |
| 9 | +// github:https://github.com/PageGuo/NewPagedFlowView | |
| 10 | + | |
| 11 | +#import <UIKit/UIKit.h> | |
| 12 | +#import "PGIndexBannerSubiew.h" | |
| 13 | + | |
| 14 | +@protocol NewPagedFlowViewDataSource; | |
| 15 | +@protocol NewPagedFlowViewDelegate; | |
| 16 | + | |
| 17 | +/****************************** | |
| 18 | + | |
| 19 | + 页面滚动的方向分为横向和纵向 | |
| 20 | + | |
| 21 | + Version 1.0: | |
| 22 | + 目的:实现类似于选择电影票的效果,并且实现无限/自动轮播 | |
| 23 | + | |
| 24 | + 特点:1.无限轮播;2.自动轮播;3.电影票样式的层次感;4.非当前显示view具有缩放和透明的特效 | |
| 25 | + | |
| 26 | + 问题:考虑到轮播图的数量不会太大,暂时未做重用处理;对设备性能影响不明显,后期版本会考虑添加重用标识模仿tableview的重用 | |
| 27 | + | |
| 28 | + ******************************/ | |
| 29 | + | |
| 30 | +typedef NS_ENUM (NSUInteger, NewPagedFlowViewOrientation) { | |
| 31 | + NewPagedFlowViewOrientationHorizontal = 0, | |
| 32 | + NewPagedFlowViewOrientationVertical = 1, | |
| 33 | +}; | |
| 34 | + | |
| 35 | +@interface NewPagedFlowView : UIView<UIScrollViewDelegate> | |
| 36 | + | |
| 37 | +/** | |
| 38 | + * 默认为横向 | |
| 39 | + */ | |
| 40 | +@property (nonatomic,assign) NewPagedFlowViewOrientation orientation; | |
| 41 | + | |
| 42 | +@property (nonatomic, strong) UIScrollView *scrollView; | |
| 43 | + | |
| 44 | +@property (nonatomic,assign) BOOL needsReload; | |
| 45 | +/** | |
| 46 | + * 总页数 | |
| 47 | + */ | |
| 48 | +@property (nonatomic,assign) NSInteger pageCount; | |
| 49 | + | |
| 50 | +@property (nonatomic,strong) NSMutableArray *cells; | |
| 51 | +@property (nonatomic,assign) NSRange visibleRange; | |
| 52 | +/** | |
| 53 | + * 如果以后需要支持reuseIdentifier,这边就得使用字典类型了 | |
| 54 | + */ | |
| 55 | +@property (nonatomic,strong) NSMutableArray *reusableCells; | |
| 56 | + | |
| 57 | +@property (nonatomic,assign) id <NewPagedFlowViewDataSource> dataSource; | |
| 58 | +@property (nonatomic,assign) id <NewPagedFlowViewDelegate> delegate; | |
| 59 | + | |
| 60 | +/** | |
| 61 | + * 指示器 | |
| 62 | + */ | |
| 63 | +@property (nonatomic,retain) UIPageControl *pageControl; | |
| 64 | + | |
| 65 | +/** | |
| 66 | + * 非当前页的透明比例 | |
| 67 | + */ | |
| 68 | +@property (nonatomic, assign) CGFloat minimumPageAlpha; | |
| 69 | + | |
| 70 | +/** | |
| 71 | + 左右间距,默认20 | |
| 72 | + */ | |
| 73 | +@property (nonatomic, assign) CGFloat leftRightMargin; | |
| 74 | + | |
| 75 | +/** | |
| 76 | + 上下间距,默认30 | |
| 77 | + */ | |
| 78 | +@property (nonatomic, assign) CGFloat topBottomMargin; | |
| 79 | + | |
| 80 | +/** | |
| 81 | + * 是否开启自动滚动,默认为开启 | |
| 82 | + */ | |
| 83 | +@property (nonatomic, assign) BOOL isOpenAutoScroll; | |
| 84 | + | |
| 85 | +/** | |
| 86 | + * 是否开启无限轮播,默认为开启 | |
| 87 | + */ | |
| 88 | +@property (nonatomic, assign) BOOL isCarousel; | |
| 89 | + | |
| 90 | +/** | |
| 91 | + * 当前是第几页 | |
| 92 | + */ | |
| 93 | +@property (nonatomic, assign, readonly) NSInteger currentPageIndex; | |
| 94 | + | |
| 95 | +/** | |
| 96 | + * 定时器 | |
| 97 | + */ | |
| 98 | +@property (nonatomic, weak) NSTimer *timer; | |
| 99 | + | |
| 100 | +/** | |
| 101 | + * 自动切换视图的时间,默认是5.0 | |
| 102 | + */ | |
| 103 | +@property (nonatomic, assign) CGFloat autoTime; | |
| 104 | + | |
| 105 | +/** | |
| 106 | + * 原始页数 | |
| 107 | + */ | |
| 108 | +@property (nonatomic, assign) NSInteger orginPageCount; | |
| 109 | + | |
| 110 | +/** | |
| 111 | + * 刷新视图 | |
| 112 | + */ | |
| 113 | +- (void)reloadData; | |
| 114 | + | |
| 115 | +/** | |
| 116 | + * 获取可重复使用的Cell | |
| 117 | + * | |
| 118 | + * @return <#return value description#> | |
| 119 | + */ | |
| 120 | +- (PGIndexBannerSubiew *)dequeueReusableCell; | |
| 121 | + | |
| 122 | +/** | |
| 123 | + * 滚动到指定的页面 | |
| 124 | + * | |
| 125 | + * @param pageNumber <#pageNumber description#> | |
| 126 | + */ | |
| 127 | +- (void)scrollToPage:(NSUInteger)pageNumber; | |
| 128 | + | |
| 129 | +/** | |
| 130 | + * 开启定时器,废弃 | |
| 131 | + */ | |
| 132 | +//- (void)startTimer; | |
| 133 | + | |
| 134 | +/** | |
| 135 | + * 关闭定时器,关闭自动滚动 | |
| 136 | + */ | |
| 137 | +- (void)stopTimer; | |
| 138 | + | |
| 139 | +/** | |
| 140 | + 调整中间页居中,经常出现滚动卡住一半时调用 | |
| 141 | + */ | |
| 142 | +- (void)adjustCenterSubview; | |
| 143 | + | |
| 144 | +@end | |
| 145 | + | |
| 146 | + | |
| 147 | +@protocol NewPagedFlowViewDelegate<NSObject> | |
| 148 | + | |
| 149 | +@optional | |
| 150 | +/** | |
| 151 | + * 当前显示cell的Size(中间页显示大小) | |
| 152 | + * | |
| 153 | + * @param flowView <#flowView description#> | |
| 154 | + * | |
| 155 | + * @return <#return value description#> | |
| 156 | + */ | |
| 157 | +- (CGSize)sizeForPageInFlowView:(NewPagedFlowView *)flowView; | |
| 158 | + | |
| 159 | +/** | |
| 160 | + * 滚动到了某一列 | |
| 161 | + * | |
| 162 | + * @param pageNumber 滚动到的列索引 | |
| 163 | + * @param flowView <#flowView description#> | |
| 164 | + */ | |
| 165 | +- (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(NewPagedFlowView *)flowView; | |
| 166 | + | |
| 167 | +/** | |
| 168 | + * 点击了第几个cell | |
| 169 | + * | |
| 170 | + * @param subView 点击的控件 | |
| 171 | + * @param subIndex 点击控件的index | |
| 172 | + * | |
| 173 | + */ | |
| 174 | +- (void)didSelectCell:(PGIndexBannerSubiew *)subView withSubViewIndex:(NSInteger)subIndex; | |
| 175 | + | |
| 176 | +/// 将要开始滚动 | |
| 177 | +/// @param scrollView 滚动的scrollView | |
| 178 | +- (void)willBeginScroll:(UIScrollView *)scrollView; | |
| 179 | + | |
| 180 | + | |
| 181 | +/// 滚动中 | |
| 182 | +/// @param scrollView 滚动的scrollView | |
| 183 | +- (void)didScroll:(UIScrollView *)scrollView; | |
| 184 | + | |
| 185 | +/// 已经结束滚动 | |
| 186 | +/// @param scrollView 滚动的scrollView | |
| 187 | +- (void)didEndScroll:(UIScrollView *)scrollView; | |
| 188 | + | |
| 189 | +@end | |
| 190 | + | |
| 191 | + | |
| 192 | +@protocol NewPagedFlowViewDataSource <NSObject> | |
| 193 | + | |
| 194 | +/** | |
| 195 | + * 返回显示View的个数 | |
| 196 | + * | |
| 197 | + * @param flowView <#flowView description#> | |
| 198 | + * | |
| 199 | + * @return <#return value description#> | |
| 200 | + */ | |
| 201 | +- (NSInteger)numberOfPagesInFlowView:(NewPagedFlowView *)flowView; | |
| 202 | + | |
| 203 | +/** | |
| 204 | + * 给某一列设置属性 | |
| 205 | + * | |
| 206 | + * @param flowView <#flowView description#> | |
| 207 | + * @param index <#index description#> | |
| 208 | + * | |
| 209 | + * @return <#return value description#> | |
| 210 | + */ | |
| 211 | +- (PGIndexBannerSubiew *)flowView:(NewPagedFlowView *)flowView cellForPageAtIndex:(NSInteger)index; | |
| 212 | + | |
| 213 | +@end | ... | ... |
metaCode/Classes/Vendors/NewPagedFlowView.m
0 → 100755
| 1 | +// | |
| 2 | +// NewPagedFlowView.m | |
| 3 | +// dianshang | |
| 4 | +// | |
| 5 | +// Created by sskh on 16/7/13. | |
| 6 | +// Copyright © 2016年 Mars. All rights reserved. | |
| 7 | +// Designed By PageGuo, | |
| 8 | +// QQ:799573715 | |
| 9 | +// github:https://github.com/PageGuo/NewPagedFlowView | |
| 10 | + | |
| 11 | +#import "NewPagedFlowView.h" | |
| 12 | + | |
| 13 | +//#import<CNLiveCommonCategory/UIColor+CNLiveExtension.h> | |
| 14 | +//#import<YYCategories/YYCategories.h> | |
| 15 | + | |
| 16 | +@interface NewPagedFlowView () | |
| 17 | + | |
| 18 | +@property (nonatomic, assign, readwrite) NSInteger currentPageIndex; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * 计时器用到的页数 | |
| 22 | + */ | |
| 23 | +@property (nonatomic, assign) NSInteger page; | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * 一页的尺寸 | |
| 27 | + */ | |
| 28 | +@property (nonatomic,assign) CGSize pageSize; | |
| 29 | + | |
| 30 | +@end | |
| 31 | + | |
| 32 | +//子控制器的类名 | |
| 33 | +static NSString *subviewClassName; | |
| 34 | + | |
| 35 | +@implementation NewPagedFlowView | |
| 36 | + | |
| 37 | +//////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 38 | +#pragma mark - | |
| 39 | +#pragma mark Private Methods | |
| 40 | +- (void)initialize{ | |
| 41 | + self.clipsToBounds = YES; | |
| 42 | + | |
| 43 | + self.needsReload = YES; | |
| 44 | + self.pageCount = 0; | |
| 45 | + self.isOpenAutoScroll = YES; | |
| 46 | + self.isCarousel = YES; | |
| 47 | + self.leftRightMargin = 20; | |
| 48 | + self.topBottomMargin = 30; | |
| 49 | + _currentPageIndex = 0; | |
| 50 | + | |
| 51 | + _minimumPageAlpha = 1.0; | |
| 52 | + _autoTime = 5.0; | |
| 53 | + | |
| 54 | + self.visibleRange = NSMakeRange(0, 0); | |
| 55 | + | |
| 56 | + self.reusableCells = [[NSMutableArray alloc] initWithCapacity:0]; | |
| 57 | + self.cells = [[NSMutableArray alloc] initWithCapacity:0]; | |
| 58 | + | |
| 59 | + self.scrollView = [[UIScrollView alloc] initWithFrame:self.bounds]; | |
| 60 | + self.scrollView.scrollsToTop = NO; | |
| 61 | + self.scrollView.delegate = self; | |
| 62 | + self.scrollView.pagingEnabled = YES; | |
| 63 | + self.scrollView.clipsToBounds = NO; | |
| 64 | + self.scrollView.showsHorizontalScrollIndicator = NO; | |
| 65 | + self.scrollView.showsVerticalScrollIndicator = NO; | |
| 66 | + | |
| 67 | + subviewClassName = @"PGIndexBannerSubiew"; | |
| 68 | + | |
| 69 | + [self addSubview:self.scrollView]; | |
| 70 | + | |
| 71 | +} | |
| 72 | + | |
| 73 | +- (void)setLeftRightMargin:(CGFloat)leftRightMargin { | |
| 74 | + _leftRightMargin = leftRightMargin * 0.5; | |
| 75 | + | |
| 76 | +} | |
| 77 | + | |
| 78 | +- (void)setTopBottomMargin:(CGFloat)topBottomMargin { | |
| 79 | + _topBottomMargin = topBottomMargin * 0.5; | |
| 80 | +} | |
| 81 | + | |
| 82 | +- (void)startTimer { | |
| 83 | + | |
| 84 | + if (self.orginPageCount > 1 && self.isOpenAutoScroll && self.isCarousel) { | |
| 85 | + NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:self.autoTime target:self selector:@selector(autoNextPage) userInfo:nil repeats:YES]; | |
| 86 | + self.timer = timer; | |
| 87 | + [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; | |
| 88 | + | |
| 89 | + } | |
| 90 | + | |
| 91 | +} | |
| 92 | + | |
| 93 | +- (void)stopTimer { | |
| 94 | + | |
| 95 | + if (self.timer) { | |
| 96 | + [self.timer invalidate]; | |
| 97 | + self.timer = nil; | |
| 98 | + } | |
| 99 | +} | |
| 100 | + | |
| 101 | +- (void)adjustCenterSubview { | |
| 102 | + if (self.isOpenAutoScroll && self.orginPageCount > 0) { | |
| 103 | + [_scrollView setContentOffset:CGPointMake(_pageSize.width * self.page, 0) animated:NO]; | |
| 104 | + } | |
| 105 | +} | |
| 106 | + | |
| 107 | +#pragma mark --自动轮播 | |
| 108 | +- (void)autoNextPage { | |
| 109 | + | |
| 110 | + self.page ++; | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + switch (self.orientation) { | |
| 115 | + case NewPagedFlowViewOrientationHorizontal:{ | |
| 116 | + | |
| 117 | + [_scrollView setContentOffset:CGPointMake(self.page * _pageSize.width, 0) animated:YES]; | |
| 118 | + break; | |
| 119 | + } | |
| 120 | + case NewPagedFlowViewOrientationVertical:{ | |
| 121 | + | |
| 122 | + [_scrollView setContentOffset:CGPointMake(0, self.page * _pageSize.height) animated:YES]; | |
| 123 | + | |
| 124 | + break; | |
| 125 | + } | |
| 126 | + default: | |
| 127 | + break; | |
| 128 | + } | |
| 129 | +} | |
| 130 | + | |
| 131 | + | |
| 132 | +- (void)queueReusableCell:(PGIndexBannerSubiew *)cell{ | |
| 133 | + [_reusableCells addObject:cell]; | |
| 134 | +} | |
| 135 | + | |
| 136 | +- (void)removeCellAtIndex:(NSInteger)index{ | |
| 137 | + PGIndexBannerSubiew *cell = [_cells objectAtIndex:index]; | |
| 138 | + if ((NSObject *)cell == [NSNull null]) { | |
| 139 | + return; | |
| 140 | + } | |
| 141 | + | |
| 142 | + [self queueReusableCell:cell]; | |
| 143 | + | |
| 144 | + if (cell.superview) { | |
| 145 | + [cell removeFromSuperview]; | |
| 146 | + } | |
| 147 | + | |
| 148 | + [_cells replaceObjectAtIndex:index withObject:[NSNull null]]; | |
| 149 | +} | |
| 150 | + | |
| 151 | +- (void)refreshVisibleCellAppearance{ | |
| 152 | + | |
| 153 | + if (_minimumPageAlpha == 1.0 && self.leftRightMargin == 0 && self.topBottomMargin == 0) { | |
| 154 | + return;//无需更新 | |
| 155 | + } | |
| 156 | + switch (self.orientation) { | |
| 157 | + case NewPagedFlowViewOrientationHorizontal:{ | |
| 158 | + CGFloat offset = _scrollView.contentOffset.x; | |
| 159 | + | |
| 160 | + for (NSInteger i = self.visibleRange.location; i < self.visibleRange.location + _visibleRange.length; i++) { | |
| 161 | + PGIndexBannerSubiew *cell = [_cells objectAtIndex:i]; | |
| 162 | + subviewClassName = NSStringFromClass([cell class]); | |
| 163 | + CGFloat origin = cell.frame.origin.x; | |
| 164 | + CGFloat delta = fabs(origin - offset); | |
| 165 | + | |
| 166 | + CGRect originCellFrame = CGRectMake(_pageSize.width * i, 0, _pageSize.width, _pageSize.height);//如果没有缩小效果的情况下的本该的Frame | |
| 167 | + | |
| 168 | + if (delta < _pageSize.width) { | |
| 169 | + | |
| 170 | +// cell.coverView.alpha = (delta / _pageSize.width) * _minimumPageAlpha; | |
| 171 | + | |
| 172 | + CGFloat leftRightInset = self.leftRightMargin * delta / _pageSize.width; | |
| 173 | + CGFloat topBottomInset = self.topBottomMargin * delta / _pageSize.width; | |
| 174 | + | |
| 175 | + cell.layer.transform = CATransform3DMakeScale((_pageSize.width-leftRightInset*2)/_pageSize.width,(_pageSize.height-topBottomInset*2)/_pageSize.height, 1.0); | |
| 176 | + cell.frame = UIEdgeInsetsInsetRect(originCellFrame, UIEdgeInsetsMake(topBottomInset, leftRightInset, topBottomInset, leftRightInset)); | |
| 177 | + | |
| 178 | + | |
| 179 | + } else { | |
| 180 | +// cell.coverView.alpha = _minimumPageAlpha; | |
| 181 | + cell.layer.transform = CATransform3DMakeScale((_pageSize.width-self.leftRightMargin*2)/_pageSize.width,(_pageSize.height-self.topBottomMargin*2)/_pageSize.height, 1.0); | |
| 182 | + cell.frame = UIEdgeInsetsInsetRect(originCellFrame, UIEdgeInsetsMake(self.topBottomMargin, self.leftRightMargin, self.topBottomMargin, self.leftRightMargin)); | |
| 183 | + | |
| 184 | + | |
| 185 | + } | |
| 186 | + | |
| 187 | + } | |
| 188 | + break; | |
| 189 | + } | |
| 190 | + case NewPagedFlowViewOrientationVertical:{ | |
| 191 | + CGFloat offset = _scrollView.contentOffset.y; | |
| 192 | + | |
| 193 | + for (NSInteger i = self.visibleRange.location; i < self.visibleRange.location + _visibleRange.length; i++) { | |
| 194 | + PGIndexBannerSubiew *cell = [_cells objectAtIndex:i]; | |
| 195 | + subviewClassName = NSStringFromClass([cell class]); | |
| 196 | + CGFloat origin = cell.frame.origin.y; | |
| 197 | + CGFloat delta = fabs(origin - offset); | |
| 198 | + | |
| 199 | + CGRect originCellFrame = CGRectMake(0, _pageSize.height * i, _pageSize.width, _pageSize.height);//如果没有缩小效果的情况下的本该的Frame | |
| 200 | + | |
| 201 | + if (delta < _pageSize.height) { | |
| 202 | +// cell.coverView.alpha = (delta / _pageSize.height) * _minimumPageAlpha; | |
| 203 | + | |
| 204 | + CGFloat leftRightInset = self.leftRightMargin * delta / _pageSize.height; | |
| 205 | + CGFloat topBottomInset = self.topBottomMargin * delta / _pageSize.height; | |
| 206 | + | |
| 207 | + cell.layer.transform = CATransform3DMakeScale((_pageSize.width-leftRightInset*2)/_pageSize.width,(_pageSize.height-topBottomInset*2) / _pageSize.height, 1.0); | |
| 208 | + cell.frame = UIEdgeInsetsInsetRect(originCellFrame, UIEdgeInsetsMake(topBottomInset, leftRightInset, topBottomInset, leftRightInset)); | |
| 209 | +// cell.mainImageView.frame = cell.bounds; | |
| 210 | + } else { | |
| 211 | +// cell.coverView.alpha = _minimumPageAlpha; | |
| 212 | + cell.frame = UIEdgeInsetsInsetRect(originCellFrame, UIEdgeInsetsMake(self.topBottomMargin, self.leftRightMargin, self.topBottomMargin, self.leftRightMargin)); | |
| 213 | +// cell.mainImageView.frame = cell.bounds; | |
| 214 | + } | |
| 215 | + | |
| 216 | + } | |
| 217 | + } | |
| 218 | + default: | |
| 219 | + break; | |
| 220 | + } | |
| 221 | + | |
| 222 | +} | |
| 223 | + | |
| 224 | +- (void)setPageAtIndex:(NSInteger)pageIndex{ | |
| 225 | + NSParameterAssert(pageIndex >= 0 && pageIndex < [_cells count]); | |
| 226 | + | |
| 227 | + PGIndexBannerSubiew *cell = [_cells objectAtIndex:pageIndex]; | |
| 228 | + | |
| 229 | + if ((NSObject *)cell == [NSNull null]) { | |
| 230 | + cell = [_dataSource flowView:self cellForPageAtIndex:pageIndex % self.orginPageCount]; | |
| 231 | + NSAssert(cell!=nil, @"datasource must not return nil"); | |
| 232 | + [_cells replaceObjectAtIndex:pageIndex withObject:cell]; | |
| 233 | + | |
| 234 | + cell.tag = pageIndex % self.orginPageCount + 100; | |
| 235 | + [cell setSubviewsWithSuperViewBounds:CGRectMake(0, 0, _pageSize.width, _pageSize.height)]; | |
| 236 | + | |
| 237 | + __weak __typeof(self) weakSelf = self; | |
| 238 | + cell.didSelectCellBlock = ^(NSInteger tag, PGIndexBannerSubiew *cell) { | |
| 239 | + [weakSelf singleCellTapAction:tag withCell:cell]; | |
| 240 | + }; | |
| 241 | + | |
| 242 | + switch (self.orientation) { | |
| 243 | + case NewPagedFlowViewOrientationHorizontal: | |
| 244 | + cell.frame = CGRectMake(_pageSize.width * pageIndex, 0, _pageSize.width, _pageSize.height); | |
| 245 | + break; | |
| 246 | + case NewPagedFlowViewOrientationVertical: | |
| 247 | + cell.frame = CGRectMake(0, _pageSize.height * pageIndex, _pageSize.width, _pageSize.height); | |
| 248 | + break; | |
| 249 | + default: | |
| 250 | + break; | |
| 251 | + } | |
| 252 | + | |
| 253 | + if (!cell.superview) { | |
| 254 | + [_scrollView addSubview:cell]; | |
| 255 | + } | |
| 256 | + } | |
| 257 | +} | |
| 258 | + | |
| 259 | + | |
| 260 | +- (void)setPagesAtContentOffset:(CGPoint)offset{ | |
| 261 | + //计算_visibleRange | |
| 262 | + CGPoint startPoint = CGPointMake(offset.x - _scrollView.frame.origin.x, offset.y - _scrollView.frame.origin.y); | |
| 263 | + CGPoint endPoint = CGPointMake(startPoint.x + self.bounds.size.width, startPoint.y + self.bounds.size.height); | |
| 264 | + | |
| 265 | + | |
| 266 | + switch (self.orientation) { | |
| 267 | + case NewPagedFlowViewOrientationHorizontal:{ | |
| 268 | + NSInteger startIndex = 0; | |
| 269 | + for (int i =0; i < [_cells count]; i++) { | |
| 270 | + if (_pageSize.width * (i +1) > startPoint.x) { | |
| 271 | + startIndex = i; | |
| 272 | + break; | |
| 273 | + } | |
| 274 | + } | |
| 275 | + | |
| 276 | + NSInteger endIndex = startIndex; | |
| 277 | + for (NSInteger i = startIndex; i < [_cells count]; i++) { | |
| 278 | + //如果都不超过则取最后一个 | |
| 279 | + if ((_pageSize.width * (i + 1) < endPoint.x && _pageSize.width * (i + 2) >= endPoint.x) || i+ 2 == [_cells count]) { | |
| 280 | + endIndex = i + 1;//i+2 是以个数,所以其index需要减去1 | |
| 281 | + break; | |
| 282 | + } | |
| 283 | + } | |
| 284 | + | |
| 285 | + //可见页分别向前向后扩展一个,提高效率 | |
| 286 | + startIndex = MAX(startIndex - 1, 0); | |
| 287 | + endIndex = MIN(endIndex + 1, [_cells count] - 1); | |
| 288 | + | |
| 289 | + // self.visibleRange.location = startIndex; | |
| 290 | + // self.visibleRange.length = endIndex - startIndex + 1; | |
| 291 | + self.visibleRange = NSMakeRange(startIndex, endIndex - startIndex + 1); | |
| 292 | + for (NSInteger i = startIndex; i <= endIndex; i++) { | |
| 293 | + [self setPageAtIndex:i]; | |
| 294 | + } | |
| 295 | + | |
| 296 | + for (int i = 0; i < startIndex; i ++) { | |
| 297 | + [self removeCellAtIndex:i]; | |
| 298 | + } | |
| 299 | + | |
| 300 | + for (NSInteger i = endIndex + 1; i < [_cells count]; i ++) { | |
| 301 | + [self removeCellAtIndex:i]; | |
| 302 | + } | |
| 303 | + break; | |
| 304 | + } | |
| 305 | + case NewPagedFlowViewOrientationVertical:{ | |
| 306 | + NSInteger startIndex = 0; | |
| 307 | + for (int i =0; i < [_cells count]; i++) { | |
| 308 | + if (_pageSize.height * (i +1) > startPoint.y) { | |
| 309 | + startIndex = i; | |
| 310 | + break; | |
| 311 | + } | |
| 312 | + } | |
| 313 | + | |
| 314 | + NSInteger endIndex = startIndex; | |
| 315 | + for (NSInteger i = startIndex; i < [_cells count]; i++) { | |
| 316 | + //如果都不超过则取最后一个 | |
| 317 | + if ((_pageSize.height * (i + 1) < endPoint.y && _pageSize.height * (i + 2) >= endPoint.y) || i+ 2 == [_cells count]) { | |
| 318 | + endIndex = i + 1;//i+2 是以个数,所以其index需要减去1 | |
| 319 | + break; | |
| 320 | + } | |
| 321 | + } | |
| 322 | + | |
| 323 | + //可见页分别向前向后扩展一个,提高效率 | |
| 324 | + startIndex = MAX(startIndex - 1, 0); | |
| 325 | + endIndex = MIN(endIndex + 1, [_cells count] - 1); | |
| 326 | + | |
| 327 | + _visibleRange.location = startIndex; | |
| 328 | + _visibleRange.length = endIndex - startIndex + 1; | |
| 329 | + | |
| 330 | + for (NSInteger i = startIndex; i <= endIndex; i++) { | |
| 331 | + [self setPageAtIndex:i]; | |
| 332 | + } | |
| 333 | + | |
| 334 | + for (NSInteger i = 0; i < startIndex; i ++) { | |
| 335 | + [self removeCellAtIndex:i]; | |
| 336 | + } | |
| 337 | + | |
| 338 | + for (NSInteger i = endIndex + 1; i < [_cells count]; i ++) { | |
| 339 | + [self removeCellAtIndex:i]; | |
| 340 | + } | |
| 341 | + break; | |
| 342 | + } | |
| 343 | + default: | |
| 344 | + break; | |
| 345 | + } | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | +} | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | +//////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 355 | +#pragma mark - | |
| 356 | +#pragma mark Override Methods | |
| 357 | + | |
| 358 | +- (id)initWithFrame:(CGRect)frame | |
| 359 | +{ | |
| 360 | + self = [super initWithFrame:frame]; | |
| 361 | + if (self) | |
| 362 | + { | |
| 363 | + [self initialize]; | |
| 364 | + } | |
| 365 | + return self; | |
| 366 | +} | |
| 367 | + | |
| 368 | +- (id)initWithCoder:(NSCoder *)aDecoder | |
| 369 | +{ | |
| 370 | + self = [super initWithCoder:aDecoder]; | |
| 371 | + if (self) | |
| 372 | + { | |
| 373 | + [self initialize]; | |
| 374 | + } | |
| 375 | + return self; | |
| 376 | +} | |
| 377 | + | |
| 378 | + | |
| 379 | +//////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 380 | +#pragma mark NewPagedFlowView API | |
| 381 | + | |
| 382 | +- (void)reloadData { | |
| 383 | + _needsReload = YES; | |
| 384 | + | |
| 385 | + //移除所有self.scrollView的子控件 | |
| 386 | + for (UIView *view in self.scrollView.subviews) { | |
| 387 | + if ([NSStringFromClass(view.class) isEqualToString:subviewClassName] || [view isKindOfClass:[PGIndexBannerSubiew class]]) { | |
| 388 | + [view removeFromSuperview]; | |
| 389 | + } | |
| 390 | + } | |
| 391 | + | |
| 392 | + [self stopTimer]; | |
| 393 | + | |
| 394 | + if (_needsReload) { | |
| 395 | + //如果需要重新加载数据,则需要清空相关数据全部重新加载 | |
| 396 | + | |
| 397 | + | |
| 398 | + //重置pageCount | |
| 399 | + if (_dataSource && [_dataSource respondsToSelector:@selector(numberOfPagesInFlowView:)]) { | |
| 400 | + | |
| 401 | + //原始页数 | |
| 402 | + self.orginPageCount = [_dataSource numberOfPagesInFlowView:self]; | |
| 403 | + | |
| 404 | + //总页数 | |
| 405 | + if (self.isCarousel) { | |
| 406 | + _pageCount = self.orginPageCount == 1 ? 1: [_dataSource numberOfPagesInFlowView:self] * 3; | |
| 407 | + }else { | |
| 408 | + _pageCount = self.orginPageCount == 1 ? 1: [_dataSource numberOfPagesInFlowView:self]; | |
| 409 | + } | |
| 410 | + | |
| 411 | + //如果总页数为0,return | |
| 412 | + if (_pageCount == 0) { | |
| 413 | + | |
| 414 | + return; | |
| 415 | + } | |
| 416 | + | |
| 417 | + if (self.pageControl && [self.pageControl respondsToSelector:@selector(setNumberOfPages:)]) { | |
| 418 | + [self.pageControl setNumberOfPages:self.orginPageCount]; | |
| 419 | + } | |
| 420 | + } | |
| 421 | + | |
| 422 | + //重置pageWidth | |
| 423 | + _pageSize = CGSizeMake(self.bounds.size.width - 4 * self.leftRightMargin,(self.bounds.size.width - 4 * self.leftRightMargin) * 9 /16); | |
| 424 | + if (self.delegate && self.delegate && [self.delegate respondsToSelector:@selector(sizeForPageInFlowView:)]) { | |
| 425 | + _pageSize = [self.delegate sizeForPageInFlowView:self]; | |
| 426 | + } | |
| 427 | + | |
| 428 | + [_reusableCells removeAllObjects]; | |
| 429 | + _visibleRange = NSMakeRange(0, 0); | |
| 430 | + | |
| 431 | + //填充cells数组 | |
| 432 | + [_cells removeAllObjects]; | |
| 433 | + for (NSInteger index=0; index<_pageCount; index++) | |
| 434 | + { | |
| 435 | + [_cells addObject:[NSNull null]]; | |
| 436 | + } | |
| 437 | + | |
| 438 | + // 重置_scrollView的contentSize | |
| 439 | + switch (self.orientation) { | |
| 440 | + case NewPagedFlowViewOrientationHorizontal://横向 | |
| 441 | + _scrollView.frame = CGRectMake(0, 0, _pageSize.width, _pageSize.height); | |
| 442 | + _scrollView.contentSize = CGSizeMake(_pageSize.width * _pageCount,0); | |
| 443 | + CGPoint theCenter = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); | |
| 444 | + _scrollView.center = theCenter; | |
| 445 | + | |
| 446 | + if (self.orginPageCount > 1) { | |
| 447 | + | |
| 448 | + if (self.isCarousel) { | |
| 449 | + | |
| 450 | + //滚到第二组 | |
| 451 | + [_scrollView setContentOffset:CGPointMake(_pageSize.width * self.orginPageCount, 0) animated:NO]; | |
| 452 | + | |
| 453 | + self.page = self.orginPageCount; | |
| 454 | + | |
| 455 | + //启动自动轮播 | |
| 456 | + [self startTimer]; | |
| 457 | + | |
| 458 | + }else { | |
| 459 | + //滚到开始 | |
| 460 | + [_scrollView setContentOffset:CGPointMake(0, 0) animated:NO]; | |
| 461 | + | |
| 462 | + self.page = self.orginPageCount; | |
| 463 | + | |
| 464 | + } | |
| 465 | + | |
| 466 | + } | |
| 467 | + | |
| 468 | + break; | |
| 469 | + case NewPagedFlowViewOrientationVertical:{ | |
| 470 | + _scrollView.frame = CGRectMake(0, 0, _pageSize.width, _pageSize.height); | |
| 471 | + _scrollView.contentSize = CGSizeMake(0 ,_pageSize.height * _pageCount); | |
| 472 | + CGPoint theCenter = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); | |
| 473 | + _scrollView.center = theCenter; | |
| 474 | + | |
| 475 | + if (self.orginPageCount > 1) { | |
| 476 | + | |
| 477 | + if (self.isCarousel) { | |
| 478 | + //滚到第二组 | |
| 479 | + [_scrollView setContentOffset:CGPointMake(0, _pageSize.height * self.orginPageCount) animated:NO]; | |
| 480 | + | |
| 481 | + self.page = self.orginPageCount; | |
| 482 | + | |
| 483 | + //启动自动轮播 | |
| 484 | + [self startTimer]; | |
| 485 | + }else { | |
| 486 | + //滚到第二组 | |
| 487 | + [_scrollView setContentOffset:CGPointMake(0, 0) animated:NO]; | |
| 488 | + | |
| 489 | + self.page = self.orginPageCount; | |
| 490 | + | |
| 491 | + } | |
| 492 | + | |
| 493 | + } | |
| 494 | + | |
| 495 | + break; | |
| 496 | + } | |
| 497 | + default: | |
| 498 | + break; | |
| 499 | + } | |
| 500 | + | |
| 501 | + _needsReload = NO; | |
| 502 | + } | |
| 503 | + | |
| 504 | + | |
| 505 | + [self setPagesAtContentOffset:_scrollView.contentOffset];//根据当前scrollView的offset设置cell | |
| 506 | + | |
| 507 | + [self refreshVisibleCellAppearance];//更新各个可见Cell的显示外貌 | |
| 508 | +} | |
| 509 | + | |
| 510 | + | |
| 511 | +- (PGIndexBannerSubiew *)dequeueReusableCell{ | |
| 512 | + PGIndexBannerSubiew *cell = [_reusableCells lastObject]; | |
| 513 | + if (cell) | |
| 514 | + { | |
| 515 | + [_reusableCells removeLastObject]; | |
| 516 | + } | |
| 517 | + | |
| 518 | + return cell; | |
| 519 | +} | |
| 520 | + | |
| 521 | +- (void)scrollToPage:(NSUInteger)pageNumber { | |
| 522 | + if (pageNumber < _pageCount) { | |
| 523 | + | |
| 524 | + //首先停止定时器 | |
| 525 | + [self stopTimer]; | |
| 526 | + | |
| 527 | + if (self.isCarousel) { | |
| 528 | + | |
| 529 | + self.page = pageNumber + self.orginPageCount; | |
| 530 | + [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(startTimer) object:nil]; | |
| 531 | + [self performSelector:@selector(startTimer) withObject:nil afterDelay:0.5]; | |
| 532 | + | |
| 533 | + }else { | |
| 534 | + self.page = pageNumber; | |
| 535 | + } | |
| 536 | + | |
| 537 | + switch (self.orientation) { | |
| 538 | + case NewPagedFlowViewOrientationHorizontal: | |
| 539 | + [_scrollView setContentOffset:CGPointMake(_pageSize.width * self.page, 0) animated:YES]; | |
| 540 | + break; | |
| 541 | + case NewPagedFlowViewOrientationVertical: | |
| 542 | + [_scrollView setContentOffset:CGPointMake(0, _pageSize.height * self.page) animated:YES]; | |
| 543 | + break; | |
| 544 | + } | |
| 545 | + [self setPagesAtContentOffset:_scrollView.contentOffset]; | |
| 546 | + [self refreshVisibleCellAppearance]; | |
| 547 | + } | |
| 548 | +} | |
| 549 | + | |
| 550 | +//////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 551 | +#pragma mark - | |
| 552 | +#pragma mark hitTest | |
| 553 | + | |
| 554 | +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { | |
| 555 | + if ([self pointInside:point withEvent:event]) { | |
| 556 | + CGPoint newPoint = CGPointZero; | |
| 557 | + newPoint.x = point.x - _scrollView.frame.origin.x + _scrollView.contentOffset.x; | |
| 558 | + newPoint.y = point.y - _scrollView.frame.origin.y + _scrollView.contentOffset.y; | |
| 559 | + if ([_scrollView pointInside:newPoint withEvent:event]) { | |
| 560 | + return [_scrollView hitTest:newPoint withEvent:event]; | |
| 561 | + } | |
| 562 | + | |
| 563 | + return _scrollView; | |
| 564 | + } | |
| 565 | + | |
| 566 | + return nil; | |
| 567 | +} | |
| 568 | + | |
| 569 | + | |
| 570 | +#pragma mark - | |
| 571 | +#pragma mark UIScrollView Delegate | |
| 572 | + | |
| 573 | +- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ | |
| 574 | + | |
| 575 | + if (self.orginPageCount == 0) { | |
| 576 | + return; | |
| 577 | + } | |
| 578 | + | |
| 579 | + NSInteger pageIndex; | |
| 580 | + | |
| 581 | + switch (self.orientation) { | |
| 582 | + case NewPagedFlowViewOrientationHorizontal: | |
| 583 | + pageIndex = (int)round(_scrollView.contentOffset.x / _pageSize.width) % self.orginPageCount; | |
| 584 | + break; | |
| 585 | + case NewPagedFlowViewOrientationVertical: | |
| 586 | + pageIndex = (int)round(_scrollView.contentOffset.y / _pageSize.height) % self.orginPageCount; | |
| 587 | + break; | |
| 588 | + default: | |
| 589 | + break; | |
| 590 | + } | |
| 591 | + | |
| 592 | + if (self.isCarousel) { | |
| 593 | + | |
| 594 | + if (self.orginPageCount > 1) { | |
| 595 | + switch (self.orientation) { | |
| 596 | + case NewPagedFlowViewOrientationHorizontal: | |
| 597 | + { | |
| 598 | + if (scrollView.contentOffset.x / _pageSize.width >= 2 * self.orginPageCount) { | |
| 599 | + | |
| 600 | + [scrollView setContentOffset:CGPointMake(_pageSize.width * self.orginPageCount, 0) animated:NO]; | |
| 601 | + | |
| 602 | + self.page = self.orginPageCount; | |
| 603 | + | |
| 604 | + } | |
| 605 | + | |
| 606 | + if (scrollView.contentOffset.x / _pageSize.width <= self.orginPageCount - 1) { | |
| 607 | + [scrollView setContentOffset:CGPointMake((2 * self.orginPageCount - 1) * _pageSize.width, 0) animated:NO]; | |
| 608 | + | |
| 609 | + self.page = 2 * self.orginPageCount; | |
| 610 | + } | |
| 611 | + | |
| 612 | + } | |
| 613 | + break; | |
| 614 | + case NewPagedFlowViewOrientationVertical: | |
| 615 | + { | |
| 616 | + if (scrollView.contentOffset.y / _pageSize.height >= 2 * self.orginPageCount) { | |
| 617 | + | |
| 618 | + [scrollView setContentOffset:CGPointMake(0, _pageSize.height * self.orginPageCount) animated:NO]; | |
| 619 | + | |
| 620 | + self.page = self.orginPageCount; | |
| 621 | + | |
| 622 | + } | |
| 623 | + | |
| 624 | + if (scrollView.contentOffset.y / _pageSize.height <= self.orginPageCount - 1) { | |
| 625 | + [scrollView setContentOffset:CGPointMake(0, (2 * self.orginPageCount - 1) * _pageSize.height) animated:NO]; | |
| 626 | + self.page = 2 * self.orginPageCount; | |
| 627 | + } | |
| 628 | + | |
| 629 | + } | |
| 630 | + break; | |
| 631 | + default: | |
| 632 | + break; | |
| 633 | + } | |
| 634 | + | |
| 635 | + | |
| 636 | + }else { | |
| 637 | + | |
| 638 | + pageIndex = 0; | |
| 639 | + | |
| 640 | + | |
| 641 | + } | |
| 642 | + } | |
| 643 | + | |
| 644 | + | |
| 645 | + [self setPagesAtContentOffset:scrollView.contentOffset]; | |
| 646 | + [self refreshVisibleCellAppearance]; | |
| 647 | + | |
| 648 | + if (self.pageControl && [self.pageControl respondsToSelector:@selector(setCurrentPage:)]) { | |
| 649 | + | |
| 650 | + [self.pageControl setCurrentPage:pageIndex]; | |
| 651 | + } | |
| 652 | + | |
| 653 | + if (_delegate && [_delegate respondsToSelector:@selector(didScrollToPage:inFlowView:)] && _currentPageIndex != pageIndex && pageIndex >= 0) { | |
| 654 | + [_delegate didScrollToPage:pageIndex inFlowView:self]; | |
| 655 | + } | |
| 656 | + | |
| 657 | + _currentPageIndex = pageIndex; | |
| 658 | + | |
| 659 | + if (self.delegate && [self.delegate respondsToSelector:@selector(didScroll:)]) { | |
| 660 | + [_delegate didScroll:self.scrollView]; | |
| 661 | + } | |
| 662 | +} | |
| 663 | + | |
| 664 | +#pragma mark --将要开始拖拽 | |
| 665 | +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { | |
| 666 | + [self stopTimer]; | |
| 667 | +} | |
| 668 | + | |
| 669 | +#pragma mark --结束拖拽 | |
| 670 | +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { | |
| 671 | + [self startTimer]; | |
| 672 | +} | |
| 673 | +//结束滑动 | |
| 674 | +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView | |
| 675 | +{ | |
| 676 | + NSLog(@"滑动结束"); | |
| 677 | + if (self.delegate && [self.delegate respondsToSelector:@selector(didEndScroll:)]) { | |
| 678 | + [self.delegate didEndScroll:self.scrollView]; | |
| 679 | + } | |
| 680 | +} | |
| 681 | +#pragma mark --将要结束拖拽 | |
| 682 | +- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { | |
| 683 | + | |
| 684 | + if (self.orginPageCount > 1 && self.isOpenAutoScroll && self.isCarousel) { | |
| 685 | + | |
| 686 | + switch (self.orientation) { | |
| 687 | + case NewPagedFlowViewOrientationHorizontal: | |
| 688 | + { | |
| 689 | + if (self.page == floor(_scrollView.contentOffset.x / _pageSize.width)) { | |
| 690 | + | |
| 691 | + self.page = floor(_scrollView.contentOffset.x / _pageSize.width) + 1; | |
| 692 | + | |
| 693 | + }else { | |
| 694 | + | |
| 695 | + self.page = floor(_scrollView.contentOffset.x / _pageSize.width); | |
| 696 | + } | |
| 697 | + } | |
| 698 | + break; | |
| 699 | + case NewPagedFlowViewOrientationVertical: | |
| 700 | + { | |
| 701 | + if (self.page == floor(_scrollView.contentOffset.y / _pageSize.height)) { | |
| 702 | + | |
| 703 | + self.page = floor(_scrollView.contentOffset.y / _pageSize.height) + 1; | |
| 704 | + | |
| 705 | + }else { | |
| 706 | + | |
| 707 | + self.page = floor(_scrollView.contentOffset.y / _pageSize.height); | |
| 708 | + } | |
| 709 | + } | |
| 710 | + break; | |
| 711 | + default: | |
| 712 | + break; | |
| 713 | + } | |
| 714 | + | |
| 715 | + } | |
| 716 | +} | |
| 717 | + | |
| 718 | +//点击了cell | |
| 719 | +- (void)singleCellTapAction:(NSInteger)selectTag withCell:(PGIndexBannerSubiew *)cell { | |
| 720 | + | |
| 721 | + if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectCell:withSubViewIndex:)]) { | |
| 722 | + | |
| 723 | + [self.delegate didSelectCell:cell withSubViewIndex:selectTag]; | |
| 724 | + | |
| 725 | + } | |
| 726 | +} | |
| 727 | + | |
| 728 | +//解决当父View释放时,当前视图因为被Timer强引用而不能释放的问题 | |
| 729 | +- (void)willMoveToSuperview:(UIView *)newSuperview { | |
| 730 | + if (!newSuperview) { | |
| 731 | + [self stopTimer]; | |
| 732 | + } | |
| 733 | +} | |
| 734 | + | |
| 735 | +//解决当timer释放后 回调scrollViewDidScroll时访问野指针导致崩溃 | |
| 736 | +- (void)dealloc { | |
| 737 | + _scrollView.delegate = nil; | |
| 738 | +} | |
| 739 | + | |
| 740 | +@end | ... | ... |
metaCode/Classes/Vendors/PGIndexBannerSubiew.h
0 → 100755
| 1 | +// | |
| 2 | +// PGIndexBannerSubiew.h | |
| 3 | +// NewPagedFlowViewDemo | |
| 4 | +// | |
| 5 | +// Created by Mars on 16/6/18. | |
| 6 | +// Copyright © 2016年 Mars. All rights reserved. | |
| 7 | +// Designed By PageGuo, | |
| 8 | +// QQ:799573715 | |
| 9 | +// github:https://github.com/PageGuo/NewPagedFlowView | |
| 10 | + | |
| 11 | +/****************************** | |
| 12 | + | |
| 13 | + 可以根据自己的需要继承PGIndexBannerSubiew | |
| 14 | + | |
| 15 | + ******************************/ | |
| 16 | + | |
| 17 | +#import <UIKit/UIKit.h> | |
| 18 | + | |
| 19 | + | |
| 20 | +@protocol PGIndexBannerSubiew <NSObject> | |
| 21 | + | |
| 22 | +@end | |
| 23 | + | |
| 24 | +@interface PGIndexBannerSubiew : UIView <PGIndexBannerSubiew> | |
| 25 | + | |
| 26 | + | |
| 27 | +@property (nonatomic, copy) void (^didSelectCellBlock)(NSInteger tag, PGIndexBannerSubiew *cell); | |
| 28 | +/// 设置子控件frame,继承后要重写 | |
| 29 | +- (void)setSubviewsWithSuperViewBounds:(CGRect)superViewBounds; | |
| 30 | + | |
| 31 | +@end | ... | ... |
metaCode/Classes/Vendors/PGIndexBannerSubiew.m
0 → 100755
| 1 | +// | |
| 2 | +// PGIndexBannerSubiew.m | |
| 3 | +// NewPagedFlowViewDemo | |
| 4 | +// | |
| 5 | +// Created by Mars on 16/6/18. | |
| 6 | +// Copyright © 2016年 Mars. All rights reserved. | |
| 7 | +// Designed By PageGuo, | |
| 8 | +// QQ:799573715 | |
| 9 | +// github:https://github.com/PageGuo/NewPagedFlowView | |
| 10 | + | |
| 11 | +#import "PGIndexBannerSubiew.h" | |
| 12 | + | |
| 13 | + | |
| 14 | +@interface PGIndexBannerSubiew() | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | +@end | |
| 20 | + | |
| 21 | +@implementation PGIndexBannerSubiew | |
| 22 | + | |
| 23 | + | |
| 24 | +- (instancetype)initWithFrame:(CGRect)frame { | |
| 25 | + | |
| 26 | + self = [super initWithFrame:frame]; | |
| 27 | + | |
| 28 | + if (self) { | |
| 29 | + | |
| 30 | + UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleCellTapAction:)]; | |
| 31 | + [self addGestureRecognizer:singleTap]; | |
| 32 | + | |
| 33 | + } | |
| 34 | + | |
| 35 | + return self; | |
| 36 | +} | |
| 37 | + | |
| 38 | +- (void)singleCellTapAction:(UIGestureRecognizer *)gesture { | |
| 39 | + if (self.didSelectCellBlock) { | |
| 40 | + self.didSelectCellBlock(self.tag, self); | |
| 41 | + } | |
| 42 | +} | |
| 43 | + | |
| 44 | +- (void)setSubviewsWithSuperViewBounds:(CGRect)superViewBounds { | |
| 45 | + | |
| 46 | +// if (CGRectEqualToRect(self.mainImageView.frame, superViewBounds)) { | |
| 47 | +// return; | |
| 48 | +// } | |
| 49 | + | |
| 50 | +// self.mainImageView.frame = superViewBounds; | |
| 51 | +// self.coverView.frame = superViewBounds; | |
| 52 | +} | |
| 53 | +@end | ... | ... |
metaCode/Classes/Vendors/WJColorChange.h
0 → 100644
| 1 | +// | |
| 2 | +// WJColorChange.h | |
| 3 | +// ColorChange | |
| 4 | +// | |
| 5 | +// Created by wangjin on 2018/8/30. | |
| 6 | +// Copyright © 2018年 ELah. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | + | |
| 12 | +@protocol WJColorChangeDelegate <NSObject> | |
| 13 | + | |
| 14 | + | |
| 15 | +/** | |
| 16 | + 滚动时候回调 传出当前的滚动视图 | |
| 17 | + | |
| 18 | + @param scrollView 滚动视图 | |
| 19 | + */ | |
| 20 | +- (void)WJColorScrollViewScroll:(UIScrollView *)scrollView; | |
| 21 | + | |
| 22 | + | |
| 23 | +/** | |
| 24 | + 滚动结束时候回调 | |
| 25 | + | |
| 26 | + @param scrollView 滚动视图 | |
| 27 | + */ | |
| 28 | +- (void)WJColorEndScroll:(UIScrollView *)scrollView; | |
| 29 | + | |
| 30 | +@end | |
| 31 | + | |
| 32 | +typedef enum : NSUInteger { | |
| 33 | + SingleColor,//背景单色 | |
| 34 | + TransverseGradientColor, // 背景横向渐变色 | |
| 35 | +} ColorType; | |
| 36 | + | |
| 37 | +@interface WJColorChange : NSObject | |
| 38 | + | |
| 39 | + | |
| 40 | +/** | |
| 41 | + 初始化对象 | |
| 42 | + | |
| 43 | + @param colorType 颜色类型设置 | |
| 44 | + @return 返回对象实体 | |
| 45 | + */ | |
| 46 | +- (instancetype)initWithType:(ColorType)colorType; | |
| 47 | + | |
| 48 | +/** | |
| 49 | + 设置颜色的方法 单色背景 | |
| 50 | + | |
| 51 | + @param scrollView 滚动的视图 | |
| 52 | + @param colorArray 颜色数组 | |
| 53 | + @param changeView 需要颜色变化的View | |
| 54 | + */ | |
| 55 | +- (void)settingScrollView:(UIScrollView*)scrollView colorArray:(NSArray<UIColor *>*)colorArray needChangeColorView:(UIView *)changeView; | |
| 56 | + | |
| 57 | + | |
| 58 | +/** | |
| 59 | + 设置颜色的方法 渐变背景 | |
| 60 | + | |
| 61 | + @param scrollView 滚动的视图 | |
| 62 | + @param colorArray 渐变颜色数组 | |
| 63 | + @param changeView 需要变化的View --- 这里不能与滚动视图同对象 | |
| 64 | + */ | |
| 65 | +- (void)settingArrayScrollView:(UIScrollView*)scrollView colorArray:(NSArray<NSArray*>*)colorArray needChangeColorView:(UIView *)changeView; | |
| 66 | + | |
| 67 | + | |
| 68 | +/** | |
| 69 | + 颜色类型 | |
| 70 | + */ | |
| 71 | +@property (nonatomic,assign) ColorType colorType; | |
| 72 | + | |
| 73 | +@property (nonatomic,weak) id<WJColorChangeDelegate> delegate; | |
| 74 | + | |
| 75 | +///UIScrollView 滑动超过多少距离后, 颜色才发生变化, 默认为0, 触发滑动就立即改变颜色 | |
| 76 | +@property (nonatomic,assign) CGFloat offset; | |
| 77 | + | |
| 78 | +@end | ... | ... |
metaCode/Classes/Vendors/WJColorChange.m
0 → 100644
| 1 | +// | |
| 2 | +// WJColorChange.m | |
| 3 | +// ColorChange | |
| 4 | +// | |
| 5 | +// Created by wangjin on 2018/8/30. | |
| 6 | +// Copyright © 2018年 ELah. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +// 增加了 横向渐变的效果 添加了 类型设置 | |
| 10 | + | |
| 11 | +#import "WJColorChange.h" | |
| 12 | + | |
| 13 | +@interface WJColorChange ()<UIScrollViewDelegate> | |
| 14 | + | |
| 15 | + | |
| 16 | +/// 单颜色视图下的背景色 | |
| 17 | +/// 开始颜色, 取值范围 0~1 | |
| 18 | +@property (nonatomic, assign) CGFloat startR; | |
| 19 | +@property (nonatomic, assign) CGFloat startG; | |
| 20 | +@property (nonatomic, assign) CGFloat startB; | |
| 21 | +/// 完成颜色, 取值范围 0~1 | |
| 22 | +@property (nonatomic, assign) CGFloat endR; | |
| 23 | +@property (nonatomic, assign) CGFloat endG; | |
| 24 | +@property (nonatomic, assign) CGFloat endB; | |
| 25 | + | |
| 26 | + | |
| 27 | +/// 渐变颜色视图下的背景色 | |
| 28 | +/// 第一部分开始颜色 | |
| 29 | +@property (nonatomic, assign) CGFloat firstStartR; | |
| 30 | +@property (nonatomic, assign) CGFloat firstStartG; | |
| 31 | +@property (nonatomic, assign) CGFloat firstStartB; | |
| 32 | + | |
| 33 | +/// 第二部分开始颜色 | |
| 34 | + | |
| 35 | +@property (nonatomic, assign) CGFloat secondStartR; | |
| 36 | +@property (nonatomic, assign) CGFloat secondStartG; | |
| 37 | +@property (nonatomic, assign) CGFloat secondStartB; | |
| 38 | + | |
| 39 | +/// 第一部分结束颜色 | |
| 40 | +@property (nonatomic, assign) CGFloat firstEndR; | |
| 41 | +@property (nonatomic, assign) CGFloat firstEndG; | |
| 42 | +@property (nonatomic, assign) CGFloat firstEndB; | |
| 43 | + | |
| 44 | +/// 第二部分结束颜色 | |
| 45 | +@property (nonatomic, assign) CGFloat secondEndR; | |
| 46 | +@property (nonatomic, assign) CGFloat secondEndG; | |
| 47 | +@property (nonatomic, assign) CGFloat secondEndB; | |
| 48 | + | |
| 49 | +/// 记录刚开始时的偏移量 | |
| 50 | +@property (nonatomic, assign) NSInteger startOffsetY; | |
| 51 | +@property (nonatomic,strong) UIScrollView *yourScrollView; | |
| 52 | + | |
| 53 | +//颜色数组 外面传进来的 | |
| 54 | +@property (nonatomic,strong) NSArray *colorArray; | |
| 55 | +//需要变化的背景视图 | |
| 56 | +@property (nonatomic,strong) UIView *needChangeView; | |
| 57 | +//渐变图层 | |
| 58 | +@property (nonatomic,strong) CAGradientLayer *gradientLayer; | |
| 59 | + | |
| 60 | +@end | |
| 61 | + | |
| 62 | +@implementation WJColorChange | |
| 63 | + | |
| 64 | +#pragma mark - PublicMethod | |
| 65 | + | |
| 66 | +- (instancetype)initWithType:(ColorType)colorType { | |
| 67 | + | |
| 68 | + if (self = [super init]) { | |
| 69 | + self.colorType = colorType; | |
| 70 | + } | |
| 71 | + return self; | |
| 72 | +} | |
| 73 | + | |
| 74 | +- (void)settingScrollView:(UIScrollView*)scrollView colorArray:(NSArray<UIColor *>*)colorArray needChangeColorView:(UIView *)changeView{ | |
| 75 | + | |
| 76 | + if (!scrollView) return; | |
| 77 | + if (!colorArray) return; | |
| 78 | + | |
| 79 | + self.yourScrollView = scrollView; | |
| 80 | + self.needChangeView = changeView; | |
| 81 | + self.colorArray = colorArray; | |
| 82 | + | |
| 83 | + scrollView.delegate = self; | |
| 84 | +} | |
| 85 | + | |
| 86 | +- (void)settingArrayScrollView:(UIScrollView*)scrollView colorArray:(NSArray<NSArray*>*)colorArray needChangeColorView:(UIView *)changeView { | |
| 87 | + | |
| 88 | + if (!scrollView) return; | |
| 89 | + if (!colorArray) return; | |
| 90 | + | |
| 91 | + self.yourScrollView = scrollView; | |
| 92 | + self.needChangeView = changeView; | |
| 93 | + self.colorArray = colorArray; | |
| 94 | + scrollView.delegate = self; | |
| 95 | + | |
| 96 | + NSArray *firstArray = colorArray.firstObject; | |
| 97 | + //默认赋值 | |
| 98 | + [self settingGradientLayerWithStartColor:firstArray[0] endColor:firstArray[1] bgView:changeView]; | |
| 99 | +} | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | +#pragma mark - PrivateMethod | |
| 104 | +- (void)settingWithStartColor:(UIColor *)startColor endColor:(UIColor *)endColor { | |
| 105 | + | |
| 106 | + [self setupStartColor:startColor]; | |
| 107 | + [self setupEndColor:endColor]; | |
| 108 | +} | |
| 109 | + | |
| 110 | + | |
| 111 | +- (void)settingTransverGradientWithFirstStartColor:(UIColor *)firstStartColor firstEndColor:(UIColor *)firstEndColor secondStartColor:(UIColor *)secondStartColor secondEndColor:(UIColor *)secondEndColor { | |
| 112 | + | |
| 113 | + [self setupFirstStartColor:firstStartColor]; | |
| 114 | + [self setupFirstEndColor:firstEndColor]; | |
| 115 | + | |
| 116 | + [self setupSecondStartColor:secondStartColor]; | |
| 117 | + [self setupSecondEndColor:secondEndColor]; | |
| 118 | + | |
| 119 | +} | |
| 120 | + | |
| 121 | + | |
| 122 | +#pragma mark - - - UIScrollViewDelegate | |
| 123 | +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView | |
| 124 | +{ | |
| 125 | + _startOffsetY = scrollView.contentOffset.y; | |
| 126 | +} | |
| 127 | + | |
| 128 | +- (void)scrollViewDidScroll:(UIScrollView *)scrollView { | |
| 129 | + | |
| 130 | + | |
| 131 | + if ([self.delegate respondsToSelector:@selector(WJColorScrollViewScroll:)]) { | |
| 132 | + | |
| 133 | + [self.delegate WJColorScrollViewScroll:scrollView]; | |
| 134 | + } | |
| 135 | + | |
| 136 | + // 1、定义获取需要的数据 | |
| 137 | + CGFloat progress = 0; | |
| 138 | + NSInteger originalIndex = 0; | |
| 139 | + NSInteger targetIndex = 0; | |
| 140 | + // 2、判断是上滑还是下滑 | |
| 141 | + CGFloat currentOffsetY = scrollView.contentOffset.y; | |
| 142 | + CGFloat scrollViewH = scrollView.bounds.size.height; | |
| 143 | + | |
| 144 | + if (currentOffsetY > _startOffsetY) { // 上滑 | |
| 145 | + | |
| 146 | + /**控制滑动中间的view,不立马进行颜色变化,超过_offset后再变化*/ | |
| 147 | + scrollViewH += _offset; | |
| 148 | + if (currentOffsetY < scrollViewH && _startOffsetY==scrollView.bounds.size.height) { | |
| 149 | + return; | |
| 150 | + } | |
| 151 | + | |
| 152 | + // 1、计算 progress | |
| 153 | + progress = currentOffsetY / scrollViewH - floor(currentOffsetY / scrollViewH); | |
| 154 | + // 2、计算 originalIndex | |
| 155 | + originalIndex = currentOffsetY / scrollViewH; | |
| 156 | + // 3、计算 targetIndex | |
| 157 | + targetIndex = originalIndex + 1; | |
| 158 | + if (targetIndex >= self.colorArray.count) { | |
| 159 | + targetIndex = self.colorArray.count - 1; | |
| 160 | + } | |
| 161 | + | |
| 162 | + | |
| 163 | + } else { // 下滑 | |
| 164 | + | |
| 165 | + /**控制滑动中间的view,不立马进行颜色变化,超过_offset后再变化*/ | |
| 166 | + scrollViewH -= _offset; | |
| 167 | + if (currentOffsetY > scrollViewH && _startOffsetY==scrollView.bounds.size.height) { | |
| 168 | + return; | |
| 169 | + } | |
| 170 | + | |
| 171 | + // 1、计算 progress | |
| 172 | + progress = 1 - (currentOffsetY / scrollViewH - floor(currentOffsetY / scrollViewH)); | |
| 173 | + // 2、计算 targetIndex | |
| 174 | + targetIndex = currentOffsetY / scrollViewH; | |
| 175 | + // 3、计算 originalIndex | |
| 176 | + originalIndex = targetIndex + 1; | |
| 177 | + if (originalIndex >= self.colorArray.count) { | |
| 178 | + originalIndex = self.colorArray.count - 1; | |
| 179 | + } | |
| 180 | + } | |
| 181 | + | |
| 182 | + //3.如果在第一个 不进行颜色改变 | |
| 183 | + if (currentOffsetY <=0) { | |
| 184 | + return; | |
| 185 | + } | |
| 186 | + | |
| 187 | + if (self.colorType == SingleColor) { | |
| 188 | + [self settingWithStartColor:self.colorArray[originalIndex] endColor:self.colorArray[targetIndex]]; | |
| 189 | + [self changeBgViewGradientEffectWithProgress:progress bgView:self.needChangeView]; | |
| 190 | + }else { | |
| 191 | + | |
| 192 | + NSArray *originalArray = self.colorArray[originalIndex]; | |
| 193 | + NSArray *targetArray = self.colorArray[targetIndex]; | |
| 194 | + [self settingTransverGradientWithFirstStartColor:originalArray[0] firstEndColor:targetArray[0] secondStartColor:originalArray[1] secondEndColor:targetArray[1]]; | |
| 195 | + [self changeTransverseViewGradientEffectWithProgress:progress bgView:self.needChangeView]; | |
| 196 | + } | |
| 197 | + | |
| 198 | +} | |
| 199 | + | |
| 200 | +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { | |
| 201 | + | |
| 202 | + if ([self.delegate respondsToSelector:@selector(WJColorEndScroll:)]) { | |
| 203 | + [self.delegate WJColorEndScroll:scrollView]; | |
| 204 | + } | |
| 205 | + | |
| 206 | + CGFloat currentOffsetY = scrollView.contentOffset.y; | |
| 207 | + CGFloat scrollViewH = scrollView.bounds.size.height; | |
| 208 | + NSInteger index = currentOffsetY / scrollViewH; | |
| 209 | + self.needChangeView.backgroundColor = self.colorArray[index]; | |
| 210 | + | |
| 211 | +} | |
| 212 | + | |
| 213 | +#pragma mark - - - 颜色渐变方法抽取 | |
| 214 | +- (void)changeBgViewGradientEffectWithProgress:(CGFloat)progress bgView:(UIView *)bgView { | |
| 215 | + | |
| 216 | + CGFloat r = self.endR - self.startR; | |
| 217 | + CGFloat g = self.endG - self.startG; | |
| 218 | + CGFloat b = self.endB - self.startB; | |
| 219 | + | |
| 220 | + UIColor *changingColor = [UIColor colorWithRed:self.startR + r * progress green:self.startG + g * progress blue:self.startB + b * progress alpha:1.0]; | |
| 221 | + bgView.backgroundColor = changingColor; | |
| 222 | +} | |
| 223 | + | |
| 224 | +- (void)changeTransverseViewGradientEffectWithProgress:(CGFloat)progress bgView:(UIView *)bgView { | |
| 225 | + | |
| 226 | + CGFloat fr = self.firstEndR - self.firstStartR; | |
| 227 | + CGFloat fg = self.firstEndG - self.firstStartG; | |
| 228 | + CGFloat fb = self.firstEndB - self.firstStartB; | |
| 229 | + | |
| 230 | + CGFloat sr = self.secondEndR - self.secondStartR; | |
| 231 | + CGFloat sg = self.secondEndG - self.secondStartG; | |
| 232 | + CGFloat sb = self.secondEndB - self.secondStartB; | |
| 233 | + | |
| 234 | + UIColor *fChangingColor = [UIColor colorWithRed:self.firstStartR + fr * progress green:self.firstStartG + fg * progress blue:self.firstStartB + fb * progress alpha:1.0]; | |
| 235 | + UIColor *sChangingColor = [UIColor colorWithRed:self.secondStartR + sr * progress green:self.secondStartG + sg * progress blue:self.secondStartB + sb * progress alpha:1.0]; | |
| 236 | + | |
| 237 | + [self settingGradientLayerWithStartColor:fChangingColor endColor:sChangingColor bgView:bgView]; | |
| 238 | +} | |
| 239 | + | |
| 240 | + | |
| 241 | +/** | |
| 242 | + 设置图层的横向渐变 | |
| 243 | + | |
| 244 | + @param startColor 开始色 | |
| 245 | + @param endColor 结束色 | |
| 246 | + @param bgView 背景视图 | |
| 247 | + */ | |
| 248 | +- (void)settingGradientLayerWithStartColor:(UIColor *)startColor endColor:(UIColor *)endColor bgView:(UIView *)bgView{ | |
| 249 | + //横向渐变的路径 | |
| 250 | + self.gradientLayer.colors = @[(__bridge id)startColor.CGColor, (__bridge id)endColor.CGColor];//这里颜色渐变 | |
| 251 | + self.gradientLayer.locations = @[@0.0, @1.0];//颜色位置 | |
| 252 | + self.gradientLayer.startPoint = CGPointMake(0, 0); | |
| 253 | + self.gradientLayer.endPoint = CGPointMake(1.0, 0); | |
| 254 | + self.gradientLayer.frame = bgView.bounds; | |
| 255 | + [bgView.layer addSublayer:self.gradientLayer]; | |
| 256 | + [bgView.layer insertSublayer:self.gradientLayer atIndex:0]; | |
| 257 | +} | |
| 258 | + | |
| 259 | +#pragma mark - - - 颜色设置的计算 | |
| 260 | + | |
| 261 | + | |
| 262 | +/** | |
| 263 | + 开始颜色设置 | |
| 264 | + | |
| 265 | + @param color 开始颜色 | |
| 266 | + */ | |
| 267 | +- (void)setupStartColor:(UIColor *)color { | |
| 268 | + | |
| 269 | + CGFloat components[3]; | |
| 270 | + [self getRGBComponents:components forColor:color]; | |
| 271 | + self.startR = components[0]; | |
| 272 | + self.startG = components[1]; | |
| 273 | + self.startB = components[2]; | |
| 274 | +} | |
| 275 | + | |
| 276 | +/** | |
| 277 | + 结束颜色设置 | |
| 278 | + | |
| 279 | + @param color 结束颜色 | |
| 280 | + */ | |
| 281 | +- (void)setupEndColor:(UIColor *)color { | |
| 282 | + | |
| 283 | + CGFloat components[3]; | |
| 284 | + [self getRGBComponents:components forColor:color]; | |
| 285 | + self.endR = components[0]; | |
| 286 | + self.endG = components[1]; | |
| 287 | + self.endB = components[2]; | |
| 288 | +} | |
| 289 | + | |
| 290 | +- (void)setupFirstStartColor:(UIColor *)color { | |
| 291 | + | |
| 292 | + CGFloat components[3]; | |
| 293 | + [self getRGBComponents:components forColor:color]; | |
| 294 | + self.firstStartR = components[0]; | |
| 295 | + self.firstStartG = components[1]; | |
| 296 | + self.firstStartB = components[2]; | |
| 297 | +} | |
| 298 | + | |
| 299 | + | |
| 300 | +- (void)setupFirstEndColor:(UIColor *)color { | |
| 301 | + | |
| 302 | + CGFloat components[3]; | |
| 303 | + [self getRGBComponents:components forColor:color]; | |
| 304 | + self.firstEndR = components[0]; | |
| 305 | + self.firstEndG = components[1]; | |
| 306 | + self.firstEndB = components[2]; | |
| 307 | +} | |
| 308 | + | |
| 309 | +- (void)setupSecondStartColor:(UIColor *)color { | |
| 310 | + CGFloat components[3]; | |
| 311 | + [self getRGBComponents:components forColor:color]; | |
| 312 | + self.secondStartR = components[0]; | |
| 313 | + self.secondStartG = components[1]; | |
| 314 | + self.secondStartB = components[2]; | |
| 315 | + | |
| 316 | +} | |
| 317 | + | |
| 318 | +- (void)setupSecondEndColor:(UIColor *)color { | |
| 319 | + | |
| 320 | + CGFloat components[3]; | |
| 321 | + [self getRGBComponents:components forColor:color]; | |
| 322 | + self.secondEndR = components[0]; | |
| 323 | + self.secondEndG = components[1]; | |
| 324 | + self.secondEndB = components[2]; | |
| 325 | +} | |
| 326 | + | |
| 327 | +/** | |
| 328 | + * 指定颜色,获取颜色的RGB值 | |
| 329 | + * | |
| 330 | + * @param components RGB数组 | |
| 331 | + * @param color 颜色 | |
| 332 | + */ | |
| 333 | +- (void)getRGBComponents:(CGFloat [3])components forColor:(UIColor *)color { | |
| 334 | + | |
| 335 | + CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB(); | |
| 336 | + unsigned char resultingPixel[4]; | |
| 337 | + CGContextRef context = CGBitmapContextCreate(&resultingPixel, 1, 1, 8, 4, rgbColorSpace, 1); | |
| 338 | + CGContextSetFillColorWithColor(context, [color CGColor]); | |
| 339 | + CGContextFillRect(context, CGRectMake(0, 0, 1, 1)); | |
| 340 | + CGContextRelease(context); | |
| 341 | + CGColorSpaceRelease(rgbColorSpace); | |
| 342 | + for (int component = 0; component < 3; component++) { | |
| 343 | + components[component] = resultingPixel[component] / 255.0f; | |
| 344 | + } | |
| 345 | +} | |
| 346 | + | |
| 347 | +#pragma mark -- set/get | |
| 348 | +- (CAGradientLayer *)gradientLayer { | |
| 349 | + | |
| 350 | + if (!_gradientLayer) { | |
| 351 | + _gradientLayer = [CAGradientLayer layer]; | |
| 352 | + } | |
| 353 | + return _gradientLayer; | |
| 354 | +} | |
| 355 | +@end | |
| 356 | + | ... | ... |
metaCode/Classes/Vendors/metaCode-Bridging-Header.h
0 → 100644
metaCode/Supporting Files/Assets.xcassets/collectMoneyImage.imageset/4661683514280_.pic.jpg
0 → 100644
75 KB
metaCode/Supporting Files/Assets.xcassets/collectMoneyImage.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "filename" : "4661683514280_.pic.jpg", | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "scale" : "3x" | |
| 15 | + } | |
| 16 | + ], | |
| 17 | + "info" : { | |
| 18 | + "author" : "xcode", | |
| 19 | + "version" : 1 | |
| 20 | + } | |
| 21 | +} | ... | ... |
metaCode/Supporting Files/Assets.xcassets/homePage_backViewImage.imageset/4671683516653_.pic.jpg
0 → 100644
82.2 KB
metaCode/Supporting Files/Assets.xcassets/homePage_backViewImage.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "filename" : "4671683516653_.pic.jpg", | |
| 5 | + "idiom" : "universal", | |
| 6 | + "scale" : "1x" | |
| 7 | + }, | |
| 8 | + { | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "scale" : "3x" | |
| 15 | + } | |
| 16 | + ], | |
| 17 | + "info" : { | |
| 18 | + "author" : "xcode", | |
| 19 | + "version" : 1 | |
| 20 | + } | |
| 21 | +} | ... | ... |
metaCode/Supporting Files/Assets.xcassets/homePage_homePage_down.imageset/4491683252485_.pic.jpg
0 → 100644
5.25 KB
metaCode/Supporting Files/Assets.xcassets/homePage_homePage_down.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "filename" : "4491683252485_.pic.jpg", | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "scale" : "3x" | |
| 15 | + } | |
| 16 | + ], | |
| 17 | + "info" : { | |
| 18 | + "author" : "xcode", | |
| 19 | + "version" : 1 | |
| 20 | + } | |
| 21 | +} | ... | ... |
metaCode/Supporting Files/Assets.xcassets/homePage_mainView_front.imageset/4621683513846_.pic.jpg
0 → 100644
56.9 KB
metaCode/Supporting Files/Assets.xcassets/homePage_mainView_front.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "filename" : "4621683513846_.pic.jpg", | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "scale" : "3x" | |
| 15 | + } | |
| 16 | + ], | |
| 17 | + "info" : { | |
| 18 | + "author" : "xcode", | |
| 19 | + "version" : 1 | |
| 20 | + } | |
| 21 | +} | ... | ... |
metaCode/Supporting Files/Assets.xcassets/homePage_payMoneyImage.imageset/4651683514228_.pic.jpg
0 → 100644
52.1 KB
metaCode/Supporting Files/Assets.xcassets/homePage_payMoneyImage.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "filename" : "4651683514228_.pic.jpg", | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "scale" : "3x" | |
| 15 | + } | |
| 16 | + ], | |
| 17 | + "info" : { | |
| 18 | + "author" : "xcode", | |
| 19 | + "version" : 1 | |
| 20 | + } | |
| 21 | +} | ... | ... |
metaCode/Supporting Files/Assets.xcassets/homePage_topImage.imageset/4771683609542_.pic.jpg
0 → 100644
230 KB
metaCode/Supporting Files/Assets.xcassets/homePage_topImage.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "filename" : "4771683609542_.pic.jpg", | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "scale" : "3x" | |
| 15 | + } | |
| 16 | + ], | |
| 17 | + "info" : { | |
| 18 | + "author" : "xcode", | |
| 19 | + "version" : 1 | |
| 20 | + } | |
| 21 | +} | ... | ... |
metaCode/Supporting Files/Assets.xcassets/homePage_zhongguorenming_bank.imageset/4431683250159_.pic.jpg
0 → 100644
79.4 KB
metaCode/Supporting Files/Assets.xcassets/homePage_zhongguorenming_bank.imageset/Contents.json
0 → 100644
| 1 | +{ | |
| 2 | + "images" : [ | |
| 3 | + { | |
| 4 | + "idiom" : "universal", | |
| 5 | + "scale" : "1x" | |
| 6 | + }, | |
| 7 | + { | |
| 8 | + "filename" : "4431683250159_.pic.jpg", | |
| 9 | + "idiom" : "universal", | |
| 10 | + "scale" : "2x" | |
| 11 | + }, | |
| 12 | + { | |
| 13 | + "idiom" : "universal", | |
| 14 | + "scale" : "3x" | |
| 15 | + } | |
| 16 | + ], | |
| 17 | + "info" : { | |
| 18 | + "author" : "xcode", | |
| 19 | + "version" : 1 | |
| 20 | + } | |
| 21 | +} | ... | ... |