├── demo.png ├── shelfmagenticGuide.png ├── shelfmagenticGuide2.png ├── ShelfMagnetic ├── ShelfMagnetic │ ├── Assets.xcassets │ │ ├── Contents.json │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── AppDelegate.h │ ├── Class │ │ ├── ShelfMagnetic.h │ │ ├── View │ │ │ ├── MagneticsMoreFooterView.m │ │ │ ├── MagneticErrorCell.m │ │ │ ├── MagneticTableFooterView.h │ │ │ ├── MagneticsMoreFooterView.h │ │ │ ├── JEBaseLoadingView.m │ │ │ ├── MagneticTableViewCell.h │ │ │ ├── MagneticTableFooterView.m │ │ │ ├── JEBaseLoadingView.h │ │ │ ├── MagneticErrorCell.h │ │ │ ├── JEBaseEmptyView.h │ │ │ ├── MagneticTableView.h │ │ │ ├── MagneticTableViewCell.m │ │ │ └── JEBaseEmptyView.m │ │ ├── Category │ │ │ ├── NSObject+Runtime.h │ │ │ ├── UIView+NetWorkError.h │ │ │ ├── NSObject+Runtime.m │ │ │ └── UIView+NetWorkError.m │ │ ├── Request │ │ │ ├── JEHttpManager.h │ │ │ └── JEHttpManager.m │ │ ├── Model │ │ │ ├── MagneticContext.m │ │ │ └── MagneticContext.h │ │ └── Controller │ │ │ ├── MagneticCollectionController.h │ │ │ ├── MagneticController.m │ │ │ ├── MagneticController.h │ │ │ └── MagneticsController.h │ ├── ViewController.h │ ├── SceneDelegate.h │ ├── Demo │ │ ├── MagneticDemoController.h │ │ ├── MagneticDemo2Controller.h │ │ ├── MagneticDemo3Controller.h │ │ ├── MagneticDemo5Controller.h │ │ ├── MagneticsDemoViewController.h │ │ ├── MagneticDemo4Controller.h │ │ ├── View │ │ │ ├── MagneticDemo5TableViewCell.h │ │ │ └── MagneticDemo5TableViewCell.m │ │ ├── MagneticDemoRequest.h │ │ ├── MagneticDemo3Controller.m │ │ ├── MagneticDemoController.m │ │ ├── MagneticDemo5Controller.m │ │ ├── MagneticDemoRequest.m │ │ ├── MagneticDemo2Controller.m │ │ ├── MagneticsDemoViewController.m │ │ └── MagneticDemo4Controller.m │ ├── main.m │ ├── ViewController.m │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ └── SceneDelegate.m ├── Pods │ ├── Target Support Files │ │ ├── Pods-ShelfMagnetic │ │ │ ├── Pods-ShelfMagnetic-frameworks-Debug-output-files.xcfilelist │ │ │ ├── Pods-ShelfMagnetic-frameworks-Release-output-files.xcfilelist │ │ │ ├── Pods-ShelfMagnetic.modulemap │ │ │ ├── Pods-ShelfMagnetic-dummy.m │ │ │ ├── Pods-ShelfMagnetic-frameworks-Debug-input-files.xcfilelist │ │ │ ├── Pods-ShelfMagnetic-frameworks-Release-input-files.xcfilelist │ │ │ ├── Pods-ShelfMagnetic-umbrella.h │ │ │ ├── Pods-ShelfMagnetic.debug.xcconfig │ │ │ ├── Pods-ShelfMagnetic.release.xcconfig │ │ │ ├── Pods-ShelfMagnetic-Info.plist │ │ │ ├── Pods-ShelfMagnetic-acknowledgements.markdown │ │ │ └── Pods-ShelfMagnetic-acknowledgements.plist │ │ ├── AFNetworking │ │ │ ├── AFNetworking.modulemap │ │ │ ├── AFNetworking-dummy.m │ │ │ ├── AFNetworking-prefix.pch │ │ │ ├── AFNetworking.xcconfig │ │ │ ├── AFNetworking.debug.xcconfig │ │ │ ├── AFNetworking.release.xcconfig │ │ │ ├── AFNetworking-Info.plist │ │ │ └── AFNetworking-umbrella.h │ │ ├── Pods-ShelfMagneticTests │ │ │ ├── Pods-ShelfMagneticTests-acknowledgements.markdown │ │ │ ├── Pods-ShelfMagneticTests.modulemap │ │ │ ├── Pods-ShelfMagneticTests-dummy.m │ │ │ ├── Pods-ShelfMagneticTests-umbrella.h │ │ │ ├── Pods-ShelfMagneticTests.debug.xcconfig │ │ │ ├── Pods-ShelfMagneticTests.release.xcconfig │ │ │ ├── Pods-ShelfMagneticTests-Info.plist │ │ │ └── Pods-ShelfMagneticTests-acknowledgements.plist │ │ └── Pods-ShelfMagneticUITests │ │ │ ├── Pods-ShelfMagneticUITests-acknowledgements.markdown │ │ │ ├── Pods-ShelfMagneticUITests.modulemap │ │ │ ├── Pods-ShelfMagneticUITests-dummy.m │ │ │ ├── Pods-ShelfMagneticUITests-umbrella.h │ │ │ ├── Pods-ShelfMagneticUITests.debug.xcconfig │ │ │ ├── Pods-ShelfMagneticUITests.release.xcconfig │ │ │ ├── Pods-ShelfMagneticUITests-Info.plist │ │ │ └── Pods-ShelfMagneticUITests-acknowledgements.plist │ ├── Manifest.lock │ └── AFNetworking │ │ ├── LICENSE │ │ ├── AFNetworking │ │ ├── AFNetworking.h │ │ ├── AFCompatibilityMacros.h │ │ └── AFSecurityPolicy.h │ │ └── UIKit+AFNetworking │ │ ├── UIKit+AFNetworking.h │ │ ├── UIActivityIndicatorView+AFNetworking.h │ │ ├── UIRefreshControl+AFNetworking.h │ │ ├── UIProgressView+AFNetworking.h │ │ ├── WKWebView+AFNetworking.h │ │ ├── UIRefreshControl+AFNetworking.m │ │ ├── UIActivityIndicatorView+AFNetworking.m │ │ ├── UIProgressView+AFNetworking.m │ │ ├── AFNetworkActivityIndicatorManager.h │ │ ├── UIImageView+AFNetworking.h │ │ ├── UIImageView+AFNetworking.m │ │ ├── AFAutoPurgingImageCache.h │ │ └── WKWebView+AFNetworking.m ├── ShelfMagnetic.xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ └── ShelfMagnetic.xcscheme ├── ShelfMagnetic.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── Podfile ├── ShelfMagneticTests │ ├── Info.plist │ └── ShelfMagneticTests.m ├── ShelfMagneticUITests │ ├── Info.plist │ └── ShelfMagneticUITests.m └── Podfile.lock ├── MyPlayground.playground ├── playground.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── contents.xcplayground ├── Contents.swift └── Resources │ └── MyView.xib ├── LICENSE ├── .gitignore ├── README.md └── Shelfmagnetic.podspec /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenson21/shelfmagnetic/HEAD/demo.png -------------------------------------------------------------------------------- /shelfmagenticGuide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenson21/shelfmagnetic/HEAD/shelfmagenticGuide.png -------------------------------------------------------------------------------- /shelfmagenticGuide2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenson21/shelfmagnetic/HEAD/shelfmagenticGuide2.png -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-frameworks-Debug-output-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-frameworks-Release-output-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/AFNetworking/AFNetworking.modulemap: -------------------------------------------------------------------------------- 1 | framework module AFNetworking { 2 | umbrella header "AFNetworking-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/AFNetworking/AFNetworking-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_AFNetworking : NSObject 3 | @end 4 | @implementation PodsDummy_AFNetworking 5 | @end 6 | -------------------------------------------------------------------------------- /MyPlayground.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_ShelfMagnetic { 2 | umbrella header "Pods-ShelfMagnetic-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_ShelfMagnetic : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_ShelfMagnetic 5 | @end 6 | -------------------------------------------------------------------------------- /MyPlayground.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticTests/Pods-ShelfMagneticTests-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | Generated by CocoaPods - https://cocoapods.org 4 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticTests/Pods-ShelfMagneticTests.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_ShelfMagneticTests { 2 | umbrella header "Pods-ShelfMagneticTests-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticUITests/Pods-ShelfMagneticUITests-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | Generated by CocoaPods - https://cocoapods.org 4 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-frameworks-Debug-input-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${PODS_ROOT}/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-frameworks.sh 2 | ${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-frameworks-Release-input-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${PODS_ROOT}/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-frameworks.sh 2 | ${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticTests/Pods-ShelfMagneticTests-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_ShelfMagneticTests : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_ShelfMagneticTests 5 | @end 6 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticUITests/Pods-ShelfMagneticUITests.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_ShelfMagneticUITests { 2 | umbrella header "Pods-ShelfMagneticUITests-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticUITests/Pods-ShelfMagneticUITests-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_ShelfMagneticUITests : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_ShelfMagneticUITests 5 | @end 6 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/AFNetworking/AFNetworking-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/ShelfMagnetic.h: -------------------------------------------------------------------------------- 1 | // 2 | // ShelfMagnetic.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/8. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MagneticController.h" 11 | #import "MagneticsController.h" 12 | 13 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /MyPlayground.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/MagneticsMoreFooterView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticsMoreFooterView.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/1/28. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticsMoreFooterView.h" 10 | 11 | @implementation MagneticsMoreFooterView 12 | 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | - (IBAction)pushMagnetic:(id)sender; 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/MagneticErrorCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticErrorCell.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticErrorCell.h" 10 | 11 | @implementation MagneticErrorCell 12 | 13 | - (void)refreshMagneticErrorView 14 | { 15 | 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/SceneDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SceneDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow * window; 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/MagneticTableFooterView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticTableFooterView.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticTableFooterView : UIView 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/MagneticsMoreFooterView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticsMoreFooterView.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jian Dong on 2021/1/28. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticsMoreFooterView : UIView 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemoController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemoController.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/8. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticController.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticDemoController : MagneticController 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemo2Controller.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemo2Controller.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/1/19. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticController.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticDemo2Controller : MagneticController 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemo3Controller.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemo3Controller.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/1/19. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticController.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticDemo3Controller : MagneticController 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemo5Controller.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemo5Controller.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/7/4. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticController.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticDemo5Controller : MagneticController 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticsDemoViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticsDemoViewController.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/1/19. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticsController.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticsDemoViewController : MagneticsController 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemo4Controller.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemo4Controller.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jian Dong on 2021/2/27. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticCollectionController.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticDemo4Controller : MagneticCollectionController 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/JEBaseLoadingView.m: -------------------------------------------------------------------------------- 1 | // 2 | // JEBaseLoadingView.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "JEBaseLoadingView.h" 10 | 11 | @implementation JEBaseLoadingView 12 | 13 | ///开始动画 14 | - (void)startAnimating{ 15 | 16 | } 17 | 18 | ///停止动画 19 | - (void)stopAnimating{ 20 | 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_ShelfMagneticVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_ShelfMagneticVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/View/MagneticDemo5TableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemo5TableViewCell.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/7/4. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticTableViewCell.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticDemo5TableViewCell : MagneticTableViewCell 14 | @property (nonatomic, copy) NSString *content; 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/AFNetworking/AFNetworking.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | PODS_BUILD_DIR = ${BUILD_DIR} 4 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 5 | PODS_ROOT = ${SRCROOT} 6 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/AFNetworking 7 | PRODUCT_BUNDLE_IDENTIFIER = com.alamofire.AFNetworking 8 | SKIP_INSTALL = YES 9 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/MagneticTableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticTableViewCell.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jian Dong on 2021/7/4. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticTableViewCell : UITableViewCell 14 | ///Background View 15 | @property (nonatomic) UIView *magneticCellBackground; 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /MyPlayground.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: A Cocoa based Playground to present user interface 2 | 3 | import AppKit 4 | import PlaygroundSupport 5 | 6 | let nibFile = NSNib.Name("MyView") 7 | var topLevelObjects : NSArray? 8 | 9 | Bundle.main.loadNibNamed(nibFile, owner:nil, topLevelObjects: &topLevelObjects) 10 | let views = (topLevelObjects as! Array).filter { $0 is NSView } 11 | 12 | // Present the view in Playground 13 | PlaygroundPage.current.liveView = views[0] as! NSView 14 | 15 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticTests/Pods-ShelfMagneticTests-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_ShelfMagneticTestsVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_ShelfMagneticTestsVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticUITests/Pods-ShelfMagneticUITests-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_ShelfMagneticUITestsVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_ShelfMagneticUITestsVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/MagneticTableFooterView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticTableFooterView.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticTableFooterView.h" 10 | 11 | @implementation MagneticTableFooterView 12 | 13 | - (instancetype)initWithFrame:(CGRect)frame { 14 | 15 | if (self = [super initWithFrame:frame]) { 16 | //一些UI 17 | } 18 | return self; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /ShelfMagnetic/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | platform :ios, '10.0' 3 | 4 | target 'ShelfMagnetic' do 5 | # Comment the next line if you don't want to use dynamic frameworks 6 | use_frameworks! 7 | 8 | # Pods for ShelfMagnetic 9 | pod 'AFNetworking' 10 | 11 | target 'ShelfMagneticTests' do 12 | inherit! :search_paths 13 | # Pods for testing 14 | end 15 | 16 | target 'ShelfMagneticUITests' do 17 | inherit! :search_paths 18 | # Pods for testing 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/JEBaseLoadingView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JEBaseLoadingView.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface JEBaseLoadingView : UIView 14 | ///旋转动画的图片。若未设置,默认加载通用loading动画。 15 | @property (nonatomic) UIImage *loadingImage; 16 | 17 | ///开始动画 18 | - (void)startAnimating; 19 | 20 | ///停止动画 21 | - (void)stopAnimating; 22 | @end 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/MagneticErrorCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticErrorCell.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticController.h" 10 | #import "UIView+NetWorkError.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface MagneticErrorCell : UITableViewCell 15 | 16 | @property (nonatomic, weak) MagneticController *magneticController; 17 | 18 | ///刷新错误视图 19 | - (void)refreshMagneticErrorView; 20 | 21 | @end 22 | 23 | NS_ASSUME_NONNULL_END 24 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | NSString * appDelegateClassName; 14 | @autoreleasepool { 15 | // Setup code that might create autoreleased objects goes here. 16 | appDelegateClassName = NSStringFromClass([AppDelegate class]); 17 | } 18 | return UIApplicationMain(argc, argv, nil, appDelegateClassName); 19 | } 20 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "MagneticsDemoViewController.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | 21 | } 22 | 23 | - (IBAction)pushMagnetic:(id)sender { 24 | MagneticsDemoViewController *magnetics = [[MagneticsDemoViewController alloc] init]; 25 | [self.navigationController pushViewController:magnetics animated:YES]; 26 | } 27 | @end 28 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/AFNetworking/AFNetworking.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | PODS_BUILD_DIR = ${BUILD_DIR} 5 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 6 | PODS_ROOT = ${SRCROOT} 7 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/AFNetworking 8 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 9 | PRODUCT_BUNDLE_IDENTIFIER = com.alamofire.AFNetworking 10 | SKIP_INSTALL = YES 11 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 12 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/AFNetworking/AFNetworking.release.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | PODS_BUILD_DIR = ${BUILD_DIR} 5 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 6 | PODS_ROOT = ${SRCROOT} 7 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/AFNetworking 8 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 9 | PRODUCT_BUNDLE_IDENTIFIER = com.alamofire.AFNetworking 10 | SKIP_INSTALL = YES 11 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 12 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Category/NSObject+Runtime.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+Runtime.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface NSObject (Runtime) 14 | ///交换方法的IMP实现 15 | bool runtimeSwizzleMethod(Class class1, SEL selector1, Class class2, SEL selector2); 16 | 17 | ///添加方法 18 | bool runtimeAddMethod(Class toClass, SEL selector, Class impClass, SEL impSelector); 19 | 20 | ///交换当前Class指定方法的IMP实现。建议在+load方法中调用。 21 | + (BOOL)runtimeSwizzleSelector:(SEL)selector1 withSelector:(SEL)selector2; 22 | @end 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemoRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemoRequest.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jian Dong on 2021/1/28. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface MagneticDemoRequest : NSObject 14 | 15 | /// GET 请求 16 | /// @param url 全路径 17 | /// @param parameters 请求参数 18 | /// @param success 成功回调 19 | /// @param failure 失败回调 20 | - (void)requestGet:(NSString *)url 21 | parameters:(NSDictionary *)parameters 22 | success:(void (^)(id responseObject))success 23 | failure:(void (^)(id error))failure; 24 | 25 | @end 26 | 27 | NS_ASSUME_NONNULL_END 28 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/JEBaseEmptyView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JEBaseEmptyView.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | typedef NS_ENUM(NSInteger, EErrorType){ 13 | EErrorTypeFailed, //加载失败 14 | EErrorTypeNoData, //无数据 15 | EErrorTypeNoNetwork //无网 16 | }; 17 | @interface JEBaseEmptyView : UIView 18 | @property (nonatomic, assign) EErrorType errorType; 19 | @property (nonatomic, strong, readonly) UIImageView *errorIconView; 20 | @property (nonatomic, strong, readonly) UILabel *errorDescLabel; 21 | 22 | - (void)addTarget:(id)target retrySelector:(SEL)selector; 23 | @end 24 | 25 | NS_ASSUME_NONNULL_END 26 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticTests/Pods-ShelfMagneticTests.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking/AFNetworking.framework/Headers" 5 | OTHER_LDFLAGS = $(inherited) -framework "AFNetworking" 6 | PODS_BUILD_DIR = ${BUILD_DIR} 7 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 9 | PODS_ROOT = ${SRCROOT}/Pods 10 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 11 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 12 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticTests/Pods-ShelfMagneticTests.release.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking/AFNetworking.framework/Headers" 5 | OTHER_LDFLAGS = $(inherited) -framework "AFNetworking" 6 | PODS_BUILD_DIR = ${BUILD_DIR} 7 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 9 | PODS_ROOT = ${SRCROOT}/Pods 10 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 11 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 12 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticUITests/Pods-ShelfMagneticUITests.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking/AFNetworking.framework/Headers" 5 | OTHER_LDFLAGS = $(inherited) -framework "AFNetworking" 6 | PODS_BUILD_DIR = ${BUILD_DIR} 7 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 9 | PODS_ROOT = ${SRCROOT}/Pods 10 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 11 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 12 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticUITests/Pods-ShelfMagneticUITests.release.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking/AFNetworking.framework/Headers" 5 | OTHER_LDFLAGS = $(inherited) -framework "AFNetworking" 6 | PODS_BUILD_DIR = ${BUILD_DIR} 7 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 8 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 9 | PODS_ROOT = ${SRCROOT}/Pods 10 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 11 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 12 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/MagneticTableView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticTableView.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @class MagneticsController; 14 | @interface MagneticTableView : UITableView 15 | 16 | @property (nonatomic, weak) NSArray *magneticControllersArray; 17 | @property (nonatomic, weak) MagneticsController *magneticsController; 18 | 19 | ///更新指定section缓存并刷新 20 | - (void)reloadSection:(NSInteger)section; 21 | 22 | ///更新指定section组缓存并刷新 23 | - (void)reloadSections:(NSArray *)sections; 24 | 25 | @end 26 | 27 | @interface NSIndexPath (MagneticTableView) 28 | ///列 29 | @property (nonatomic, assign) NSInteger column; 30 | 31 | @end 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagneticTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagneticUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Request/JEHttpManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // JEHttpManager.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface JEHttpManager : NSObject 14 | 15 | /// 请求 16 | /// @param requestType 请求类型 17 | /// @param url 全路径 18 | /// @param parameters 请求参数 19 | /// @param success 成功回调 20 | /// @param failure 失败回调 21 | + (void)requestType:(NSInteger)requestType 22 | requestUrl:(NSString *)url 23 | parameters:(NSDictionary *)parameters 24 | success:(void (^)(id responseObject))success 25 | failure:(void (^)(id error))failure; 26 | 27 | @end 28 | 29 | NS_ASSUME_NONNULL_END 30 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/MagneticTableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticTableViewCell.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/7/4. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticTableViewCell.h" 10 | 11 | @implementation MagneticTableViewCell 12 | 13 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ 14 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { 15 | [self.contentView addSubview:self.magneticCellBackground]; 16 | } 17 | return self; 18 | } 19 | 20 | - (UIView *)magneticCellBackground{ 21 | if (!_magneticCellBackground) { 22 | _magneticCellBackground = [[UIView alloc] init]; 23 | _magneticCellBackground.hidden = YES; 24 | } 25 | return _magneticCellBackground; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking/AFNetworking.framework/Headers" 5 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 6 | OTHER_LDFLAGS = $(inherited) -framework "AFNetworking" 7 | PODS_BUILD_DIR = ${BUILD_DIR} 8 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 10 | PODS_ROOT = ${SRCROOT}/Pods 11 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 12 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 13 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic.release.xcconfig: -------------------------------------------------------------------------------- 1 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking/AFNetworking.framework/Headers" 5 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 6 | OTHER_LDFLAGS = $(inherited) -framework "AFNetworking" 7 | PODS_BUILD_DIR = ${BUILD_DIR} 8 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 10 | PODS_ROOT = ${SRCROOT}/Pods 11 | PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates 12 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 13 | -------------------------------------------------------------------------------- /ShelfMagnetic/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - AFNetworking (4.0.1): 3 | - AFNetworking/NSURLSession (= 4.0.1) 4 | - AFNetworking/Reachability (= 4.0.1) 5 | - AFNetworking/Security (= 4.0.1) 6 | - AFNetworking/Serialization (= 4.0.1) 7 | - AFNetworking/UIKit (= 4.0.1) 8 | - AFNetworking/NSURLSession (4.0.1): 9 | - AFNetworking/Reachability 10 | - AFNetworking/Security 11 | - AFNetworking/Serialization 12 | - AFNetworking/Reachability (4.0.1) 13 | - AFNetworking/Security (4.0.1) 14 | - AFNetworking/Serialization (4.0.1) 15 | - AFNetworking/UIKit (4.0.1): 16 | - AFNetworking/NSURLSession 17 | 18 | DEPENDENCIES: 19 | - AFNetworking 20 | 21 | SPEC REPOS: 22 | trunk: 23 | - AFNetworking 24 | 25 | SPEC CHECKSUMS: 26 | AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce 27 | 28 | PODFILE CHECKSUM: 1c099066449b11e0bc7bd1d67c42b09f2c3d9ff1 29 | 30 | COCOAPODS: 1.11.3 31 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - AFNetworking (4.0.1): 3 | - AFNetworking/NSURLSession (= 4.0.1) 4 | - AFNetworking/Reachability (= 4.0.1) 5 | - AFNetworking/Security (= 4.0.1) 6 | - AFNetworking/Serialization (= 4.0.1) 7 | - AFNetworking/UIKit (= 4.0.1) 8 | - AFNetworking/NSURLSession (4.0.1): 9 | - AFNetworking/Reachability 10 | - AFNetworking/Security 11 | - AFNetworking/Serialization 12 | - AFNetworking/Reachability (4.0.1) 13 | - AFNetworking/Security (4.0.1) 14 | - AFNetworking/Serialization (4.0.1) 15 | - AFNetworking/UIKit (4.0.1): 16 | - AFNetworking/NSURLSession 17 | 18 | DEPENDENCIES: 19 | - AFNetworking 20 | 21 | SPEC REPOS: 22 | trunk: 23 | - AFNetworking 24 | 25 | SPEC CHECKSUMS: 26 | AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce 27 | 28 | PODFILE CHECKSUM: 1c099066449b11e0bc7bd1d67c42b09f2c3d9ff1 29 | 30 | COCOAPODS: 1.11.3 31 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/AFNetworking/AFNetworking-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 4.0.1 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticTests/Pods-ShelfMagneticTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticTests/Pods-ShelfMagneticTests-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Generated by CocoaPods - https://cocoapods.org 18 | Title 19 | 20 | Type 21 | PSGroupSpecifier 22 | 23 | 24 | StringsTable 25 | Acknowledgements 26 | Title 27 | Acknowledgements 28 | 29 | 30 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticUITests/Pods-ShelfMagneticUITests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagneticUITests/Pods-ShelfMagneticUITests-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Generated by CocoaPods - https://cocoapods.org 18 | Title 19 | 20 | Type 21 | PSGroupSpecifier 22 | 23 | 24 | StringsTable 25 | Acknowledgements 26 | Title 27 | Acknowledgements 28 | 29 | 30 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagneticTests/ShelfMagneticTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ShelfMagneticTests.m 3 | // ShelfMagneticTests 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ShelfMagneticTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation ShelfMagneticTests 16 | 17 | - (void)setUp { 18 | // Put setup code here. This method is called before the invocation of each test method in the class. 19 | } 20 | 21 | - (void)tearDown { 22 | // Put teardown code here. This method is called after the invocation of each test method in the class. 23 | } 24 | 25 | - (void)testExample { 26 | // This is an example of a functional test case. 27 | // Use XCTAssert and related functions to verify your tests produce the correct results. 28 | } 29 | 30 | - (void)testPerformanceExample { 31 | // This is an example of a performance test case. 32 | [self measureBlock:^{ 33 | // Put the code you want to measure the time of here. 34 | }]; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Jenson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/AFNetworking/AFNetworking-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | #import "AFNetworking.h" 14 | #import "AFHTTPSessionManager.h" 15 | #import "AFURLSessionManager.h" 16 | #import "AFCompatibilityMacros.h" 17 | #import "AFNetworkReachabilityManager.h" 18 | #import "AFSecurityPolicy.h" 19 | #import "AFURLRequestSerialization.h" 20 | #import "AFURLResponseSerialization.h" 21 | #import "AFAutoPurgingImageCache.h" 22 | #import "AFImageDownloader.h" 23 | #import "AFNetworkActivityIndicatorManager.h" 24 | #import "UIActivityIndicatorView+AFNetworking.h" 25 | #import "UIButton+AFNetworking.h" 26 | #import "UIImageView+AFNetworking.h" 27 | #import "UIKit+AFNetworking.h" 28 | #import "UIProgressView+AFNetworking.h" 29 | #import "UIRefreshControl+AFNetworking.h" 30 | #import "WKWebView+AFNetworking.h" 31 | 32 | FOUNDATION_EXPORT double AFNetworkingVersionNumber; 33 | FOUNDATION_EXPORT const unsigned char AFNetworkingVersionString[]; 34 | 35 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2020 Alamofire Software Foundation (http://alamofire.org/) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Category/UIView+NetWorkError.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+NetWorkError.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "JEBaseEmptyView.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface UIView (NetWorkError) 15 | @property (nonatomic) JEBaseEmptyView *errorView; 16 | 17 | 18 | - (void)showFailedError:(id)target selector:(SEL)selector; 19 | - (void)showFailedMessage:(NSString *)message target:(id)target selector:(SEL)selector; 20 | /** 21 | * 网络错误提示 22 | * 提示语:message,默认为"您还没有连接网络" 23 | * 图片:默认为"error_network" 24 | * 按钮:默认为"error_refresh" 25 | */ 26 | - (void)showNetworkError:(id)target selector:(SEL)selector; 27 | - (void)showNetworkMessage:(NSString *)message target:(id)target selector:(SEL)selector; 28 | 29 | /** 30 | * 默认空数据提示 31 | * 提示语:message,默认为"未获取到内容" 32 | * 图片:默认为"error_empty" 33 | * 按钮:默认为nil 34 | */ 35 | - (void)showEmptyError:(id)target selector:(SEL)selector; 36 | - (void)showEmptyMessage:(NSString *)message target:(id)target selector:(SEL)selector; 37 | 38 | ///隐藏并清除提示视图 39 | - (void)hideErrorView; 40 | @end 41 | 42 | NS_ASSUME_NONNULL_END 43 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/View/MagneticDemo5TableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemo5TableViewCell.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/7/4. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticDemo5TableViewCell.h" 10 | 11 | @interface MagneticDemo5TableViewCell() 12 | @property (nonatomic) UILabel *labelTitle; 13 | @end 14 | 15 | @implementation MagneticDemo5TableViewCell 16 | 17 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 18 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { 19 | _labelTitle = [[UILabel alloc] init]; 20 | _labelTitle.textAlignment = NSTextAlignmentCenter; 21 | _labelTitle.backgroundColor = UIColor.magentaColor; 22 | [self.magneticCellBackground addSubview:_labelTitle]; 23 | } 24 | return self; 25 | } 26 | 27 | - (void)layoutSubviews{ 28 | [super layoutSubviews]; 29 | _labelTitle.frame = CGRectMake(15, 15, self.magneticCellBackground.bounds.size.width - 30, self.magneticCellBackground.bounds.size.height - 30); 30 | } 31 | 32 | - (void)setContent:(NSString *)content{ 33 | _content = content; 34 | _labelTitle.text = _content; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | 4 | ## AFNetworking 5 | 6 | Copyright (c) 2011-2020 Alamofire Software Foundation (http://alamofire.org/) 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | 26 | Generated by CocoaPods - https://cocoapods.org 27 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | 24 | #pragma mark - UISceneSession lifecycle 25 | 26 | 27 | - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)){ 28 | // Called when a new scene session is being created. 29 | // Use this method to select a configuration to create the new scene with. 30 | return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; 31 | } 32 | 33 | 34 | - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions API_AVAILABLE(ios(13.0)){ 35 | // Called when the user discards a scene session. 36 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 37 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 38 | } 39 | 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Category/NSObject+Runtime.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+Runtime.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "NSObject+Runtime.h" 10 | #import 11 | 12 | @implementation NSObject (Runtime) 13 | //添加方法 14 | bool runtimeAddMethod(Class toClass, SEL selector, Class impClass, SEL impSelector) 15 | { 16 | Method impMethod = class_getInstanceMethod(impClass, impSelector); 17 | return class_addMethod(toClass, selector, method_getImplementation(impMethod), method_getTypeEncoding(impMethod)); 18 | } 19 | 20 | //交换方法的IMP实现 21 | bool runtimeSwizzleMethod(Class class1, SEL selector1, Class class2, SEL selector2) 22 | { 23 | Method method1 = class_getInstanceMethod(class1, selector1); 24 | Method method2 = class_getInstanceMethod(class2, selector2); 25 | if (!method1 || !method2) { 26 | return false; 27 | } 28 | 29 | //为class添加方法,否则有可能交换父类IMP 30 | class_addMethod(class1, selector1, method_getImplementation(method1), method_getTypeEncoding(method1)); 31 | class_addMethod(class2, selector2, method_getImplementation(method2), method_getTypeEncoding(method2)); 32 | 33 | //重新获取添加后的method,并交换IMP 34 | method_exchangeImplementations(class_getInstanceMethod(class1, selector1), class_getInstanceMethod(class2, selector2)); 35 | 36 | return true; 37 | } 38 | 39 | //交换方法的IMP实现 40 | + (BOOL)runtimeSwizzleSelector:(SEL)selector1 withSelector:(SEL)selector2 41 | { 42 | return runtimeSwizzleMethod(self, selector1, self, selector2); 43 | } 44 | @end 45 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagneticUITests/ShelfMagneticUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ShelfMagneticUITests.m 3 | // ShelfMagneticUITests 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ShelfMagneticUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation ShelfMagneticUITests 16 | 17 | - (void)setUp { 18 | // Put setup code here. This method is called before the invocation of each test method in the class. 19 | 20 | // In UI tests it is usually best to stop immediately when a failure occurs. 21 | self.continueAfterFailure = NO; 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | - (void)tearDown { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | } 29 | 30 | - (void)testExample { 31 | // UI tests must launch the application that they test. 32 | XCUIApplication *app = [[XCUIApplication alloc] init]; 33 | [app launch]; 34 | 35 | // Use recording to get started writing UI tests. 36 | // Use XCTAssert and related functions to verify your tests produce the correct results. 37 | } 38 | 39 | - (void)testLaunchPerformance { 40 | if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { 41 | // This measures how long it takes to launch your application. 42 | [self measureWithMetrics:@[XCTOSSignpostMetric.applicationLaunchMetric] block:^{ 43 | [[[XCUIApplication alloc] init] launch]; 44 | }]; 45 | } 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/AFNetworking/AFNetworking.h: -------------------------------------------------------------------------------- 1 | // AFNetworking.h 2 | // 3 | // Copyright (c) 2013 AFNetworking (http://afnetworking.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import 25 | #import 26 | 27 | #ifndef _AFNETWORKING_ 28 | #define _AFNETWORKING_ 29 | 30 | #import "AFURLRequestSerialization.h" 31 | #import "AFURLResponseSerialization.h" 32 | #import "AFSecurityPolicy.h" 33 | 34 | #if !TARGET_OS_WATCH 35 | #import "AFNetworkReachabilityManager.h" 36 | #endif 37 | 38 | #import "AFURLSessionManager.h" 39 | #import "AFHTTPSessionManager.h" 40 | 41 | #endif /* _AFNETWORKING_ */ 42 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemo3Controller.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemo3Controller.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/1/19. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticDemo3Controller.h" 10 | 11 | @implementation MagneticDemo3Controller 12 | 13 | ///完成初始化监听 14 | - (void)didFinishInitConfigurationInMagneticsController:(MagneticsController *)magneticsController { 15 | 16 | self.isPrepared = self.magneticContext.json; 17 | 18 | } 19 | 20 | #pragma mark - Magnetic Content 21 | - (UIColor *)magneticsController:(MagneticController *)magneticsController colorForMagneticBackgroundInTableView:(MagneticTableView *)tableView{ 22 | return [UIColor clearColor]; 23 | } 24 | 25 | // 内容行数 26 | - (NSInteger)magneticsController:(MagneticController *)magneticsController rowCountForMagneticContentInTableView:(MagneticTableView *)tableView{ 27 | return self.isPrepared ? 1 : 0; 28 | } 29 | 30 | // 内容行高 31 | - (CGFloat)magneticsController:(MagneticController *)magneticsController rowHeightForMagneticContentAtIndex:(NSInteger)index{ 32 | return 100; 33 | } 34 | 35 | //复用内容视图 36 | - (void)magneticsController:(MagneticsController *)magneticsController reuseCell:(UITableViewCell *)cell forMagneticContentAtIndex:(NSInteger)index{ 37 | UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 100)]; 38 | label.textAlignment = NSTextAlignmentCenter; 39 | label.text = self.magneticContext.json; 40 | label.backgroundColor = [UIColor orangeColor]; 41 | [cell addSubview:label]; 42 | } 43 | 44 | ///磁片间距大小。默认为10.0,当高度为0.0时无间距(不占用cell)。 45 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticSpacingInTableView:(MagneticTableView *)tableView { 46 | return 10.0; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | # CocoaPods 34 | # 35 | # We recommend against adding the Pods directory to your .gitignore. However 36 | # you should judge for yourself, the pros and cons are mentioned at: 37 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 38 | # 39 | # Pods/ 40 | # 41 | # Add this line if you want to avoid checking in source code from the Xcode workspace 42 | # *.xcworkspace 43 | 44 | # Carthage 45 | # 46 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 47 | # Carthage/Checkouts 48 | 49 | Carthage/Build/ 50 | 51 | # fastlane 52 | # 53 | # It is recommended to not store the screenshots in the git repo. 54 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 55 | # For more information about the recommended setup visit: 56 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 57 | 58 | fastlane/report.xml 59 | fastlane/Preview.html 60 | fastlane/screenshots/**/*.png 61 | fastlane/test_output 62 | 63 | # Code Injection 64 | # 65 | # After new code Injection tools there's a generated folder /iOSInjectionProject 66 | # https://github.com/johnno1962/injectionforxcode 67 | 68 | iOSInjectionProject/ 69 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/UIKit+AFNetworking.h: -------------------------------------------------------------------------------- 1 | // UIKit+AFNetworking.h 2 | // 3 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | 25 | #ifndef _UIKIT_AFNETWORKING_ 26 | #define _UIKIT_AFNETWORKING_ 27 | 28 | #if TARGET_OS_IOS || TARGET_OS_TV 29 | #import "AFAutoPurgingImageCache.h" 30 | #import "AFImageDownloader.h" 31 | #import "UIActivityIndicatorView+AFNetworking.h" 32 | #import "UIButton+AFNetworking.h" 33 | #import "UIImageView+AFNetworking.h" 34 | #import "UIProgressView+AFNetworking.h" 35 | #endif 36 | 37 | #if TARGET_OS_IOS 38 | #import "AFNetworkActivityIndicatorManager.h" 39 | #import "UIRefreshControl+AFNetworking.h" 40 | #import "WKWebView+AFNetworking.h" 41 | #endif 42 | 43 | #endif /* _UIKIT_AFNETWORKING_ */ 44 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /MyPlayground.playground/Resources/MyView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Model/MagneticContext.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticContext.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticContext.h" 10 | 11 | @implementation MagneticHeaderContext 12 | @end 13 | 14 | @implementation MagneticContext 15 | 16 | - (void)setType:(MagneticType)type{ 17 | if (_type != type) { 18 | _type = type; 19 | 20 | self.clazz = [self parseClassName:type]; 21 | } 22 | } 23 | 24 | - (void)setExtensionType:(MagneticType)extensionType{ 25 | if (_extensionType != extensionType) { 26 | _extensionType = extensionType; 27 | 28 | self.extensionClazz = [self parseClassName:extensionType]; 29 | } 30 | } 31 | 32 | - (void)setJson:(id)json{ 33 | if (_json != json) { 34 | _json = json; 35 | 36 | self.error = nil; 37 | } 38 | } 39 | 40 | - (void)setError:(NSError *)error{ 41 | if (_error != error) { 42 | _error = error; 43 | 44 | _state = error ? MagneticStateError : MagneticStateNormal; 45 | } 46 | } 47 | 48 | - (void)setHeaderContext:(MagneticHeaderContext *)headerContext { 49 | if (_headerContext != headerContext) { 50 | _headerContext = headerContext; 51 | _headerContext.magneticContext = self; 52 | } 53 | } 54 | 55 | #pragma mark - Parse 56 | 57 | - (NSString *)parseClassName:(MagneticType)type{ 58 | NSString *className = nil; 59 | switch (type) { 60 | case MagneticTypeDemo: 61 | className = @"MagneticDemoController"; 62 | break; 63 | case MagneticTypeDemo2: 64 | className = @"MagneticDemo2Controller"; 65 | break; 66 | case MagneticTypeDemo3: 67 | className = @"MagneticDemo3Controller"; 68 | break; 69 | case MagneticTypeDemo4: 70 | className = @"MagneticDemo4Controller"; 71 | break; 72 | case MagneticTypeDemo5: 73 | className = @"MagneticDemo5Controller"; 74 | break; 75 | default: 76 | break; 77 | } 78 | return className; 79 | } 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemoController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemoController.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/8. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticDemoController.h" 10 | 11 | @implementation MagneticDemoController 12 | 13 | #pragma mark Magnetic Content 14 | 15 | ///完成初始化监听 16 | - (void)didFinishInitConfigurationInMagneticsController:(MagneticsController *)magneticsController { 17 | 18 | //数据处理,接口请求成功后 19 | self.isPrepared = YES; 20 | 21 | } 22 | 23 | ///请求的url, 异步请求必须实现 24 | - (NSString *)magneticRequestURLInMagneticsController:(MagneticsController *)magneticsController{ 25 | return @"https://github.com/jenson21/shelfmagnetic"; 26 | } 27 | ///请求的参数 28 | - (NSDictionary *)magneticRequestParametersInMagneticsController:(MagneticsController *)magneticsController{ 29 | return nil; 30 | } 31 | 32 | //内容行数 33 | - (NSInteger)magneticsController:(MagneticsController *)magneticsController rowCountForMagneticContentInTableView:(MagneticTableView *)tableView{ 34 | return self.isPrepared ? 1 : 0; 35 | } 36 | 37 | //内容行高 38 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController rowHeightForMagneticContentAtIndex:(NSInteger)index{ 39 | return 100.0; 40 | } 41 | 42 | //复用内容视图 43 | - (void)magneticsController:(MagneticsController *)magneticsController reuseCell:(UITableViewCell *)cell forMagneticContentAtIndex:(NSInteger)index{ 44 | UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 100)]; 45 | label.textAlignment = NSTextAlignmentCenter; 46 | label.text = @"ONE"; 47 | label.backgroundColor = [UIColor blueColor]; 48 | [cell addSubview:label]; 49 | } 50 | 51 | #pragma mark Magnetic Spacing 52 | 53 | //磁片底部间距 54 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticSpacingInTableView:(MagneticTableView *)tableView{ 55 | return 10.0; 56 | } 57 | 58 | #pragma mark Magnetic Error 59 | 60 | //是否显示磁片错误提示 61 | - (BOOL)magneticsController:(MagneticsController *)magneticsController shouldShowMagneticErrorWithCode:(MagneticErrorCode)errorCode{ 62 | return NO; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.h: -------------------------------------------------------------------------------- 1 | // UIActivityIndicatorView+AFNetworking.h 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import 23 | 24 | #import 25 | 26 | #if TARGET_OS_IOS || TARGET_OS_TV 27 | 28 | #import 29 | 30 | /** 31 | This category adds methods to the UIKit framework's `UIActivityIndicatorView` class. The methods in this category provide support for automatically starting and stopping animation depending on the loading state of a session task. 32 | */ 33 | @interface UIActivityIndicatorView (AFNetworking) 34 | 35 | ///---------------------------------- 36 | /// @name Animating for Session Tasks 37 | ///---------------------------------- 38 | 39 | /** 40 | Binds the animating state to the state of the specified task. 41 | 42 | @param task The task. If `nil`, automatic updating from any previously specified operation will be disabled. 43 | */ 44 | - (void)setAnimatingWithStateOfTask:(nullable NSURLSessionTask *)task; 45 | 46 | @end 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIMainStoryboardFile 45 | Main 46 | UIRequiredDeviceCapabilities 47 | 48 | armv7 49 | 50 | UISupportedInterfaceOrientations 51 | 52 | UIInterfaceOrientationPortrait 53 | UIInterfaceOrientationLandscapeLeft 54 | UIInterfaceOrientationLandscapeRight 55 | 56 | UISupportedInterfaceOrientations~ipad 57 | 58 | UIInterfaceOrientationPortrait 59 | UIInterfaceOrientationPortraitUpsideDown 60 | UIInterfaceOrientationLandscapeLeft 61 | UIInterfaceOrientationLandscapeRight 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.h: -------------------------------------------------------------------------------- 1 | // UIRefreshControl+AFNetworking.m 2 | // 3 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | 25 | #import 26 | 27 | #if TARGET_OS_IOS 28 | 29 | #import 30 | 31 | NS_ASSUME_NONNULL_BEGIN 32 | 33 | /** 34 | This category adds methods to the UIKit framework's `UIRefreshControl` class. The methods in this category provide support for automatically beginning and ending refreshing depending on the loading state of a session task. 35 | */ 36 | @interface UIRefreshControl (AFNetworking) 37 | 38 | ///----------------------------------- 39 | /// @name Refreshing for Session Tasks 40 | ///----------------------------------- 41 | 42 | /** 43 | Binds the refreshing state to the state of the specified task. 44 | 45 | @param task The task. If `nil`, automatic updating from any previously specified operation will be disabled. 46 | */ 47 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task; 48 | 49 | @end 50 | 51 | NS_ASSUME_NONNULL_END 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Model/MagneticContext.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticContext.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | //磁片类型 14 | typedef NS_ENUM(NSInteger, MagneticType) { 15 | MagneticTypeDemo = 1001, 16 | MagneticTypeDemo2 = 1002, 17 | MagneticTypeDemo3 = 1003, 18 | MagneticTypeDemo4 = 1004, 19 | MagneticTypeDemo5 = 1005 20 | }; 21 | ///磁片状态 22 | typedef NS_ENUM(NSInteger, MagneticState) { 23 | ///默认状态 24 | MagneticStateNormal, 25 | ///加载状态 26 | MagneticStateLoading, 27 | ///错误状态 28 | MagneticStateError, 29 | }; 30 | 31 | ///磁片错误类型 32 | typedef NS_ENUM(NSInteger, MagneticErrorCode) { 33 | ///无错误 34 | MagneticErrorCodeNone = 0, 35 | ///网络错误 36 | MagneticErrorCodeNetwork = -5500, 37 | ///数据错误 38 | MagneticErrorCodeFailed = -5501, 39 | }; 40 | 41 | @class MagneticContext; 42 | 43 | @interface MagneticHeaderContext : NSObject 44 | 45 | @property (nonatomic, weak) MagneticContext *magneticContext; 46 | @end 47 | 48 | @interface MagneticContext : NSObject 49 | 50 | ///header 51 | @property (nonatomic) MagneticHeaderContext *headerContext; 52 | 53 | ///磁片控制器Class 54 | @property (nonatomic, copy) NSString *clazz; 55 | 56 | ///组件id 57 | @property (nonatomic, copy) NSString *magneticId; 58 | 59 | ///磁片顺序 60 | @property (nonatomic, assign) NSInteger magneticIndex; 61 | 62 | ///是否支持加载更多 63 | @property (nonatomic, assign) BOOL hasMore; 64 | 65 | ///是否异步请求 66 | @property (nonatomic, assign) BOOL asyncLoad; 67 | @property (nonatomic, assign) NSInteger currentIndex; 68 | 69 | ///类型 70 | @property (nonatomic) MagneticType type; 71 | 72 | ///状态 73 | @property (nonatomic) MagneticState state; 74 | 75 | ///磁片信息(CMS配置的原始数据) 76 | @property (nonatomic) NSDictionary *magneticInfo; 77 | 78 | ///数据源,可为model 79 | @property (nonatomic) id json; 80 | 81 | ///错误 82 | @property (nonatomic) NSError * __nullable error; 83 | 84 | /** 85 | * Extension 86 | * @brief 扩展区 87 | */ 88 | 89 | ///扩展区类型 90 | @property (nonatomic) MagneticType extensionType; 91 | 92 | ///扩展控制器Class 93 | @property (nonatomic, copy) NSString *extensionClazz; 94 | // 数据源是否更改 95 | @property (nonatomic, assign) BOOL isChange; 96 | @end 97 | 98 | NS_ASSUME_NONNULL_END 99 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/AFNetworking/AFCompatibilityMacros.h: -------------------------------------------------------------------------------- 1 | // AFCompatibilityMacros.h 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #ifndef AFCompatibilityMacros_h 23 | #define AFCompatibilityMacros_h 24 | 25 | #ifdef API_AVAILABLE 26 | #define AF_API_AVAILABLE(...) API_AVAILABLE(__VA_ARGS__) 27 | #else 28 | #define AF_API_AVAILABLE(...) 29 | #endif // API_AVAILABLE 30 | 31 | #ifdef API_UNAVAILABLE 32 | #define AF_API_UNAVAILABLE(...) API_UNAVAILABLE(__VA_ARGS__) 33 | #else 34 | #define AF_API_UNAVAILABLE(...) 35 | #endif // API_UNAVAILABLE 36 | 37 | #if __has_warning("-Wunguarded-availability-new") 38 | #define AF_CAN_USE_AT_AVAILABLE 1 39 | #else 40 | #define AF_CAN_USE_AT_AVAILABLE 0 41 | #endif 42 | 43 | #if ((__IPHONE_OS_VERSION_MAX_ALLOWED && __IPHONE_OS_VERSION_MAX_ALLOWED < 100000) || (__MAC_OS_VERSION_MAX_ALLOWED && __MAC_OS_VERSION_MAX_ALLOWED < 101200) ||(__WATCH_OS_MAX_VERSION_ALLOWED && __WATCH_OS_MAX_VERSION_ALLOWED < 30000) ||(__TV_OS_MAX_VERSION_ALLOWED && __TV_OS_MAX_VERSION_ALLOWED < 100000)) 44 | #define AF_CAN_INCLUDE_SESSION_TASK_METRICS 0 45 | #else 46 | #define AF_CAN_INCLUDE_SESSION_TASK_METRICS 1 47 | #endif 48 | 49 | #endif /* AFCompatibilityMacros_h */ 50 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/SceneDelegate.m: -------------------------------------------------------------------------------- 1 | #import "SceneDelegate.h" 2 | 3 | @interface SceneDelegate () 4 | 5 | @end 6 | 7 | @implementation SceneDelegate 8 | 9 | 10 | - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)){ 11 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 12 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 13 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 14 | } 15 | 16 | 17 | - (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){ 18 | // Called as the scene is being released by the system. 19 | // This occurs shortly after the scene enters the background, or when its session is discarded. 20 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 21 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 22 | } 23 | 24 | 25 | - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){ 26 | // Called when the scene has moved from an inactive state to an active state. 27 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 28 | } 29 | 30 | 31 | - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){ 32 | // Called when the scene will move from an active state to an inactive state. 33 | // This may occur due to temporary interruptions (ex. an incoming phone call). 34 | } 35 | 36 | 37 | - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){ 38 | // Called as the scene transitions from the background to the foreground. 39 | // Use this method to undo the changes made on entering the background. 40 | } 41 | 42 | 43 | - (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){ 44 | // Called as the scene transitions from the foreground to the background. 45 | // Use this method to save data, release shared resources, and store enough scene-specific state information 46 | // to restore the scene back to its current state. 47 | } 48 | 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/Target Support Files/Pods-ShelfMagnetic/Pods-ShelfMagnetic-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Copyright (c) 2011-2020 Alamofire Software Foundation (http://alamofire.org/) 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in 27 | all copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35 | THE SOFTWARE. 36 | 37 | License 38 | MIT 39 | Title 40 | AFNetworking 41 | Type 42 | PSGroupSpecifier 43 | 44 | 45 | FooterText 46 | Generated by CocoaPods - https://cocoapods.org 47 | Title 48 | 49 | Type 50 | PSGroupSpecifier 51 | 52 | 53 | StringsTable 54 | Acknowledgements 55 | Title 56 | Acknowledgements 57 | 58 | 59 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemo5Controller.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemo5Controller.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/7/4. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticDemo5Controller.h" 10 | #import "MagneticDemo5TableViewCell.h" 11 | 12 | @implementation MagneticDemo5Controller 13 | ///完成初始化监听 14 | - (void)didFinishInitConfigurationInMagneticsController:(MagneticsController *)magneticsController { 15 | 16 | self.isPrepared = self.magneticContext.json; 17 | 18 | } 19 | 20 | #pragma mark - Magnetic Content 21 | - (UIColor *)magneticsController:(MagneticController *)magneticsController colorForMagneticBackgroundInTableView:(MagneticTableView *)tableView{ 22 | return [UIColor clearColor]; 23 | } 24 | 25 | // 内容行数 26 | - (NSInteger)magneticsController:(MagneticController *)magneticsController rowCountForMagneticContentInTableView:(MagneticTableView *)tableView{ 27 | return self.isPrepared ? 1 : 0; 28 | } 29 | 30 | // 内容行高 31 | - (CGFloat)magneticsController:(MagneticController *)magneticsController rowHeightForMagneticContentAtIndex:(NSInteger)index{ 32 | return 200; 33 | } 34 | 35 | ///磁片间距大小。默认为10.0,当高度为0.0时无间距(不占用cell)。 36 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticSpacingInTableView:(MagneticTableView *)tableView { 37 | return 10.0; 38 | } 39 | 40 | ///内容视图Class。默认为UITableViewCell。 41 | - (Class)magneticsController:(MagneticsController *)magneticsController cellClassForMagneticContentAtIndex:(NSInteger)index{ 42 | return MagneticDemo5TableViewCell.class; 43 | } 44 | 45 | ///复用内容视图 46 | - (void)magneticsController:(MagneticsController *)magneticsController reuseCell:(UITableViewCell *)cell forMagneticContentAtIndex:(NSInteger)index{ 47 | if ([cell isKindOfClass:MagneticDemo5TableViewCell.class]) { 48 | ((MagneticDemo5TableViewCell *)cell).content = self.magneticContext.json; 49 | } 50 | } 51 | ///是否展示磁片背景 52 | - (BOOL)magneticsController:(MagneticsController *)magneticsController isShowMagneticBackground:(UIView *)magneticBackground aTableView:(MagneticTableView *)tableView{ 53 | magneticBackground.backgroundColor = UIColor.systemYellowColor; 54 | magneticBackground.layer.cornerRadius = 8; 55 | magneticBackground.frame = CGRectMake(15, 0, UIScreen.mainScreen.bounds.size.width - 30, magneticBackground.frame.size.height); 56 | return YES; 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.h: -------------------------------------------------------------------------------- 1 | // UIProgressView+AFNetworking.h 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import 23 | 24 | #import 25 | 26 | #if TARGET_OS_IOS || TARGET_OS_TV 27 | 28 | #import 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | 33 | /** 34 | This category adds methods to the UIKit framework's `UIProgressView` class. The methods in this category provide support for binding the progress to the upload and download progress of a session task. 35 | */ 36 | @interface UIProgressView (AFNetworking) 37 | 38 | ///------------------------------------ 39 | /// @name Setting Session Task Progress 40 | ///------------------------------------ 41 | 42 | /** 43 | Binds the progress to the upload progress of the specified session task. 44 | 45 | @param task The session task. 46 | @param animated `YES` if the change should be animated, `NO` if the change should happen immediately. 47 | */ 48 | - (void)setProgressWithUploadProgressOfTask:(NSURLSessionUploadTask *)task 49 | animated:(BOOL)animated; 50 | 51 | /** 52 | Binds the progress to the download progress of the specified session task. 53 | 54 | @param task The session task. 55 | @param animated `YES` if the change should be animated, `NO` if the change should happen immediately. 56 | */ 57 | - (void)setProgressWithDownloadProgressOfTask:(NSURLSessionDownloadTask *)task 58 | animated:(BOOL)animated; 59 | 60 | @end 61 | 62 | NS_ASSUME_NONNULL_END 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Controller/MagneticCollectionController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticCollectionController.h 3 | // gaolvgo 4 | // 5 | // Created by Jenson on 2021/2/26. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticController.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @protocol MagneticCollectionControllerProtocol 14 | 15 | #pragma mark -datasource 16 | ///数量 17 | - (NSInteger)collectionViewNumberOfItemsInCollectionView:(UICollectionView *)collectionView; 18 | 19 | ///tableviewcell subview -> collectionView -> collectionViewCell 's size 20 | - (CGSize)collectionViewItemSizeInCollectionView:(UICollectionView *)collectionView sizeForItemAtIndexPath:(NSIndexPath *)indexPath; 21 | 22 | ///collection的高度 23 | - (CGFloat)collectionViewHeightInCollectionView:(UICollectionView *)collectionView; 24 | 25 | 26 | #pragma mark -delegate 27 | ///组件内部collectionview reusecell 28 | - (void)magneticsController:(MagneticsController *)magneticsController collectionViewReuseCell:(UICollectionViewCell *)cell indexPath:(NSIndexPath *)indexPath; 29 | 30 | @optional 31 | 32 | ///collectionView 元数据 class ,默认 [UICollectionViewCell class] 33 | - (Class)collectionViewCellClassInCollectionView:(UICollectionView *)collectionView; 34 | 35 | ///注册UICollectionViewCell标识符,默认 默认为"CellClass_MagneticType"的形式。 36 | - (NSString *)collectionViewCellIdentifierInCollectionView:(UICollectionView *)collectionView; 37 | 38 | ///点击组件内部collectionview的元视图内容事件 39 | - (void)magneticsController:(MagneticsController *)magneticsController didSelectItemAtIndexPath:(NSIndexPath *)indexPath collectionView:(UICollectionView *)collectionView; 40 | 41 | ///元视图横向间距,default is 0,因为是横划 所以LineSpacing 为横向间距 42 | - (CGFloat)collectionViewMinimumLineSpacingInCollectionView:(UICollectionView *)collectionView; 43 | 44 | ///元视图纵向间距,default is 0 45 | - (CGFloat)collectionViewMinimumInteritemSpacingInCollectionView:(UICollectionView *)collectionView; 46 | 47 | ///collection section inset default is UIEdgeInsetsZero 48 | - (UIEdgeInsets)collectionViewSectionInsetInCollectionView:(UICollectionView *)collectionView; 49 | 50 | 51 | ///footer more 52 | ///collectionView最后是否有footerCell 例如更多 53 | - (BOOL)collectionViewCanShowFooterInCollectionView:(UICollectionView *)collectionView; 54 | ///footer class UICollectionViewCell 子类,默认为UICollectionViewCell 55 | - (Class)collectionViewFooterCellClassInCollectionView:(UICollectionView *)collectionView; 56 | 57 | @end 58 | 59 | @interface MagneticCollectionController : MagneticController 60 | @property (nonatomic, strong, readonly) UICollectionView *collectionView; 61 | @property (nonatomic, weak) id collectionDelegate; 62 | @property (nonatomic, assign) UICollectionViewScrollDirection scrollDirection; 63 | @end 64 | 65 | NS_ASSUME_NONNULL_END 66 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemoRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemoRequest.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/1/28. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticDemoRequest.h" 10 | #import "AFHTTPSessionManager.h" 11 | 12 | @interface MagneticDemoRequest () 13 | 14 | @property (nonatomic) AFHTTPSessionManager *manager; 15 | @property (nonatomic, assign) BOOL hasNetWork; 16 | @property (nonatomic, copy, readwrite) NSString * reachabilityStatus; 17 | 18 | @end 19 | 20 | @implementation MagneticDemoRequest 21 | 22 | /// GET 请求 23 | /// @param url 全路径 24 | /// @param parameters 请求参数 25 | /// @param success 成功回调 26 | /// @param failure 失败回调 27 | - (void)requestGet:(NSString *)url 28 | parameters:(NSDictionary *)parameters 29 | success:(void (^)(id responseObject))success 30 | failure:(void (^)(id error))failure{ 31 | 32 | [self.manager GET:url parameters:parameters headers:@{} progress:^(NSProgress * _Nonnull downloadProgress) { 33 | 34 | } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { 35 | dispatch_async(dispatch_get_main_queue(), ^{ 36 | 37 | NSDictionary * dic; 38 | if([responseObject isKindOfClass:[NSData class]]){ 39 | dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:NULL]; 40 | }else if([responseObject isKindOfClass:[NSDictionary class]]){ 41 | dic = responseObject; 42 | }else{ 43 | failure(nil); 44 | } 45 | if (success) { 46 | success(dic); 47 | } 48 | }); 49 | } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { 50 | dispatch_async(dispatch_get_main_queue(), ^{ 51 | if (failure) { 52 | failure(error); 53 | } 54 | }); 55 | }]; 56 | 57 | } 58 | 59 | - (AFHTTPSessionManager *)manager{ 60 | if (!_manager) { 61 | _manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:@"HOST_URL"]]; 62 | [_manager operationQueue].maxConcurrentOperationCount = 5; 63 | _manager.requestSerializer = [AFHTTPRequestSerializer serializer]; // 上传普通格式 64 | // 超时时间 65 | _manager.requestSerializer.timeoutInterval = 15; 66 | // 设置请求头 67 | [_manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 68 | // 设置接收的Content-Type 69 | _manager.responseSerializer.acceptableContentTypes = [[NSSet alloc] initWithObjects:@"application/xml", @"text/xml",@"text/html", @"application/json",@"text/plain",nil]; 70 | [_manager.requestSerializer setValue:@"" forHTTPHeaderField:@"Set-Cookie"]; 71 | } 72 | return _manager; 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Category/UIView+NetWorkError.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+NetWorkError.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "UIView+NetWorkError.h" 10 | #import 11 | 12 | @implementation UIView (NetWorkError) 13 | - (void)setErrorView:(JEBaseEmptyView *)errorView { 14 | objc_setAssociatedObject(self, @selector(errorView), errorView, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 15 | } 16 | 17 | - (JEBaseEmptyView *)errorView { 18 | JEBaseEmptyView *view = objc_getAssociatedObject(self, @selector(errorView)); 19 | if (!view) { 20 | view = [[JEBaseEmptyView alloc] initWithFrame:CGRectZero]; 21 | view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 22 | self.errorView = view; 23 | } 24 | return view; 25 | } 26 | 27 | 28 | - (void)showFailedError:(id)target selector:(SEL)selector { 29 | [self showFailedMessage:@"" target:target selector:selector]; 30 | } 31 | - (void)showFailedMessage:(NSString *)message target:(id)target selector:(SEL)selector { 32 | [self showMessage:message errorType:EErrorTypeFailed target:target selector:selector]; 33 | } 34 | 35 | /** 36 | * 网络错误提示 37 | * 提示语:message,默认为"您还没有连接网络" 38 | * 图片:默认为"error_network" 39 | * 按钮:默认为"error_refresh" 40 | */ 41 | - (void)showNetworkError:(id)target selector:(SEL)selector { 42 | [self showNetworkMessage:@"" target:target selector:selector]; 43 | } 44 | - (void)showNetworkMessage:(NSString *)message target:(id)target selector:(SEL)selector { 45 | [self showMessage:message errorType:EErrorTypeNoNetwork target:target selector:selector]; 46 | } 47 | 48 | 49 | - (void)showEmptyError:(id)target selector:(SEL)selector { 50 | [self showEmptyMessage:@"" target:target selector:selector]; 51 | } 52 | 53 | - (void)showEmptyMessage:(NSString *)message target:(id)target selector:(SEL)selector { 54 | [self showMessage:message errorType:EErrorTypeNoData target:target selector:selector]; 55 | } 56 | 57 | - (void)showMessage:(NSString *)message errorType:(EErrorType)type target:(id)target selector:(SEL)selector { 58 | [self.errorView addTarget:target retrySelector:selector]; 59 | self.errorView.errorType = type; 60 | if (message) { 61 | self.errorView.errorDescLabel.text = message; 62 | } 63 | if (![self.subviews containsObject:self.errorView]) { 64 | [self addSubview:self.errorView]; 65 | } 66 | self.errorView.frame = self.bounds; 67 | } 68 | /** 69 | * @brief 显示错误提示视图 70 | * @param message 提示语。支持和NSString。 71 | * @param image 图片 72 | * @param params 扩展参数 73 | * buttonIcon UIImage * 按钮图标,默认为nil。设置target和selector时才显示。 74 | * paddingTop CGFloat 上边距,默认自动适配。距屏幕顶端1/4屏幕高度,或整体居中。 75 | * paddingBottom CGFloat 下边距,默认自动适配。距屏幕底端90,或整体居中。 76 | * @param target 点击事件target 77 | * @param selector 点击事件selector 78 | */ 79 | - (void)showErrorMessage:(id)message 80 | image:(UIImage *)image 81 | params:(NSDictionary *)params 82 | target:(id)target 83 | selector:(SEL)selector { 84 | 85 | } 86 | 87 | ///隐藏并清除提示视图 88 | - (void)hideErrorView { 89 | [self.errorView removeFromSuperview]; 90 | } 91 | @end 92 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemo2Controller.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemo2Controller.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/1/19. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticDemo2Controller.h" 10 | 11 | @implementation MagneticDemo2Controller 12 | 13 | ///完成初始化监听 14 | - (void)didFinishInitConfigurationInMagneticsController:(MagneticsController *)magneticsController { 15 | 16 | self.isPrepared = self.magneticContext.json; 17 | 18 | } 19 | 20 | /** 21 | * Magnetic Spacing 22 | * @brief 磁片头部间距 23 | */ 24 | 25 | ///磁片头部间距大小。默认为0.0,当高度为0.0时无间距(不占用cell)。 26 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticHeaderSpacingInTableView:(MagneticTableView *)tableView{ 27 | return 20; 28 | } 29 | 30 | ///磁片头部间距颜色。默认为透明。 31 | - (UIColor *)magneticsController:(MagneticsController *)magneticsController colorForMagneticHeaderSpacingInTableView:(MagneticTableView *)tableView{ 32 | return [UIColor lightGrayColor]; 33 | } 34 | 35 | /** 36 | * Magnetic Header 37 | * @brief 磁片头部 38 | */ 39 | 40 | ///是否显示头部视图。默认为NO。 41 | - (BOOL)magneticsController:(MagneticsController *)magneticsController shouldShowMagneticHeaderInTableView:(MagneticTableView *)tableView{ 42 | return YES; 43 | } 44 | 45 | ///头部行高 46 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticHeaderInTableView:(MagneticTableView *)tableView{ 47 | return 50; 48 | } 49 | 50 | ///复用头部视图 51 | - (void)magneticsController:(MagneticsController *)magneticsController reuseCell:(UITableViewCell *)cell forMagneticHeaderInTableView:(MagneticTableView *)tableView{ 52 | UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 50)]; 53 | title.font = [UIFont boldSystemFontOfSize:10]; 54 | title.textColor = [UIColor whiteColor]; 55 | title.text = @"TWO Title"; 56 | title.backgroundColor = UIColor.blackColor; 57 | title.textAlignment = NSTextAlignmentCenter; 58 | [cell.contentView addSubview:title]; 59 | } 60 | 61 | #pragma mark - Magnetic Content 62 | - (UIColor *)magneticsController:(MagneticController *)magneticsController colorForMagneticBackgroundInTableView:(MagneticTableView *)tableView{ 63 | return [UIColor clearColor]; 64 | } 65 | 66 | // 内容行数 67 | - (NSInteger)magneticsController:(MagneticController *)magneticsController rowCountForMagneticContentInTableView:(MagneticTableView *)tableView{ 68 | return self.isPrepared ? 1 : 0; 69 | } 70 | 71 | // 内容行高 72 | - (CGFloat)magneticsController:(MagneticController *)magneticsController rowHeightForMagneticContentAtIndex:(NSInteger)index{ 73 | return 200; 74 | } 75 | 76 | //复用内容视图 77 | - (void)magneticsController:(MagneticsController *)magneticsController reuseCell:(UITableViewCell *)cell forMagneticContentAtIndex:(NSInteger)index{ 78 | UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 200)]; 79 | label.textAlignment = NSTextAlignmentCenter; 80 | label.text = self.magneticContext.json; 81 | label.backgroundColor = [UIColor yellowColor]; 82 | [cell.contentView addSubview:label]; 83 | } 84 | 85 | ///磁片间距大小。默认为10.0,当高度为0.0时无间距(不占用cell)。 86 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticSpacingInTableView:(MagneticTableView *)tableView { 87 | return 10.0; 88 | } 89 | @end 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # shelfmagnetic 2 | Shelfmagnetic architecture is a combination of years of development experience 3 | 4 | # swift in development... 5 | [swift](https://github.com/jenson21/JEMagnetic_swift) 6 | 7 | # Background 8 | During the development process, you will encounter a page that displays a variety of different styles of content, or dynamically displays a certain section. If you put them in VC, then VC will be very bloated and inconvenient to manage. Then this framework came into being to solve this problem. 9 | This framework includes multi-page integration and matching, network requests, data buried points, asynchronous UI rendering, etc. Easy to use, just use VC inheritance. 10 | 11 | # Installation with CocoaPods 12 | To integrate Shelfmagnetic into your Xcode project using CocoaPods, specify it in your Podfile: 13 | `pod 'Shelfmagnetic', '~> 0.1.0'` 14 | 15 | # Architecture 16 | - Model 17 | - MagneticContext 18 | - View 19 | - MagneticTableView 20 | - MagneticErrorCell 21 | - JEBaseLoadingView 22 | - MagneticTableFooterView 23 | - JEBaseEmptyView 24 | - Controller 25 | - MagneticController 26 | - MagneticsController 27 | - MagneticCollectionController 28 | - MagneticsControllerProtocol 29 | 30 | # Image 31 | ![image](https://github.com/jenson21/shelfmagnetic/blob/master/shelfmagenticGuide.png) 32 | 33 | # Usage 34 | - Register the controller 35 | - MagneticContext.h 36 | ``` 37 | typedef NS_ENUM(NSInteger, MagneticType) { 38 | MagneticTypeDemo = 1000, 39 | }; 40 | ``` 41 | 42 | - MagneticContext.m 43 | ``` 44 | - (NSString *)parseClassName:(MagneticType)type 45 | { 46 | NSString *className = nil; 47 | switch (type) { 48 | case MagneticTypeNormal: 49 | className = @"MagneticTypeDemo"; 50 | break; 51 | default: 52 | break; 53 | } 54 | return className; 55 | } 56 | ``` 57 | 58 | - ViewController inherit MagneticsController And implement some functions. Can contain multiple MagneticDemoController. 59 | - ViewController 60 | ``` 61 | @interface ViewController : MagneticsController 62 | 63 | NSMutableArray *dataArr = [NSMutableArray array]; 64 | MagneticContext *context = [[MagneticContext alloc]init]; 65 | context.type = MagneticTypeDemo; 66 | [dataArr addObject:context]; 67 | 68 | /** 69 | dataArr add more VC 70 | */ 71 | [self requestMagneticsDidSucceedWithMagneticsArray:dataArr]; 72 | ``` 73 | 74 | - MagneticDemoController inherit MagneticController And implement some functions. 75 | - MagneticDemoController 76 | 77 | ``` 78 | - (void)didFinishInitConfigurationInCardsController:(CardsController *)cardsController { 79 | // After completing initial monitoring, data processing, and successful interface request 80 | } 81 | 82 | - (NSString *)magneticRequestURLInMagneticsController:(MagneticsController *)magneticsController{ 83 | //Request url, asynchronous request must be implemented 84 | return @"https://github.com/jenson21/shelfmagnetic"; 85 | } 86 | 87 | - (NSDictionary *)magneticRequestParametersInMagneticsController:(MagneticsController *)magneticsController{ 88 | //Requested parameters 89 | return nil; 90 | } 91 | ``` 92 | 93 | # contact 94 | * jenson.pitaya@outlook.com 95 | 96 | # License 97 | Shelfmagnetic is released under the MIT license. See [LICENSE](https://github.com/jenson21/shelfmagnetic/blob/master/LICENSE) for details. 98 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Controller/MagneticController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticController.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticController.h" 10 | #import "MagneticsController.h" 11 | 12 | @interface MagneticController () 13 | 14 | /* Cache */ 15 | @property (nonatomic, assign) BOOL showMagneticError; 16 | @property (nonatomic, assign) BOOL showMagneticHeader; 17 | @property (nonatomic, assign) BOOL showMagneticFooter; 18 | @property (nonatomic, assign) BOOL showMagneticHeaderSpacing; 19 | @property (nonatomic, assign) BOOL showMagneticSpacing; 20 | @property (nonatomic, assign) NSInteger rowCountCache; 21 | @property (nonatomic, assign) NSInteger extensionRowIndex; 22 | @property (nonatomic, copy) NSArray *rowHeightsCache; 23 | /* RequestMore */ 24 | @property (nonatomic) BOOL canRequestMoreData; 25 | 26 | @end 27 | 28 | 29 | @implementation MagneticController 30 | 31 | - (void)dealloc{ 32 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 33 | 34 | } 35 | 36 | - (instancetype)init{ 37 | self = [super init]; 38 | if (self) { 39 | } 40 | return self; 41 | } 42 | 43 | 44 | #pragma mark - Property 45 | 46 | - (void)setMagneticContext:(MagneticContext *)magneticContext{ 47 | _magneticContext = magneticContext; 48 | } 49 | 50 | - (void)setIsPrepared:(BOOL)isPrepared{ 51 | if (_isPrepared != isPrepared) { 52 | _isPrepared = isPrepared; 53 | 54 | [self.delegate refreshMagneticWithType:self.magneticContext.type]; 55 | } 56 | } 57 | 58 | 59 | 60 | #pragma mark - Lazy Loading 61 | 62 | #pragma mark Magnetic Content 63 | 64 | //内容行数 65 | - (NSInteger)magneticsController:(MagneticsController *)magneticsController rowCountForMagneticContentInTableView:(MagneticTableView *)tableView{ 66 | return 0; 67 | } 68 | 69 | //内容行高 70 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController rowHeightForMagneticContentAtIndex:(NSInteger)index{ 71 | return 0.0; 72 | } 73 | 74 | //复用内容视图 75 | - (void)magneticsController:(MagneticsController *)magneticsController reuseCell:(UITableViewCell *)cell forMagneticContentAtIndex:(NSInteger)index{ 76 | 77 | } 78 | 79 | #pragma mark Magnetic Spacing 80 | 81 | //磁片头部间距 82 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticHeaderSpacingInTableView:(MagneticTableView *)tableView{ 83 | return 0.0; 84 | } 85 | 86 | //磁片底部间距 87 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticSpacingInTableView:(MagneticTableView *)tableView{ 88 | return 10.0; 89 | } 90 | 91 | #pragma mark Magnetic Error 92 | 93 | //是否显示磁片错误提示 94 | - (BOOL)magneticsController:(MagneticsController *)magneticsController shouldShowMagneticErrorWithCode:(MagneticErrorCode)errorCode{ 95 | return NO; 96 | } 97 | 98 | 99 | 100 | #pragma mark - Error 101 | 102 | //请求错误磁片数据 103 | - (void)requestErrorMagneticData{ 104 | MagneticErrorCode errorCode = _magneticContext.error.code; 105 | if (errorCode == MagneticErrorCodeNetwork || errorCode == MagneticErrorCodeFailed) { //磁片请求失败 106 | //显示加载状态 107 | _magneticContext.state = MagneticStateLoading; 108 | [self.magneticsController refreshMagneticWithType:_magneticContext.type]; 109 | 110 | //重新请求数据 111 | [self.magneticsController requestMagneticDataWithController:self]; 112 | } 113 | } 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticsDemoViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticsDemoViewController.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2021/1/19. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticsDemoViewController.h" 10 | 11 | /// 是否刘海屏 12 | #define kIsBangsScreen ({\ 13 | BOOL isBangsScreen = NO; \ 14 | if (@available(iOS 11.0, *)) { \ 15 | UIWindow *window = [[UIApplication sharedApplication].windows firstObject]; \ 16 | isBangsScreen = window.safeAreaInsets.bottom > 0; \ 17 | } \ 18 | isBangsScreen; \ 19 | }) 20 | 21 | #define kTabbarHeight (kIsBangsScreen?83.0:49.0) 22 | #define kNavgationbarHeight (kIsBangsScreen?88.0:64.0) 23 | #define kStatusBarHeight (kIsBangsScreen?44.0:20.0) 24 | #define kSafeAreaInsetsBottom (kIsBangsScreen?34.0:0.0) 25 | 26 | @interface MagneticsDemoViewController () 27 | 28 | @end 29 | 30 | @implementation MagneticsDemoViewController 31 | 32 | - (void)viewDidLoad { 33 | [super viewDidLoad]; 34 | 35 | self.tableView.frame = CGRectMake(0, kNavgationbarHeight, self.view.bounds.size.width, self.view.bounds.size.height - kNavgationbarHeight); 36 | 37 | self.refreshType = MagneticsRefreshTypePullToRefresh | MagneticsRefreshTypeInfiniteScrolling; 38 | NSMutableArray *dataArr = [NSMutableArray array]; 39 | //demo 40 | MagneticContext *context = [[MagneticContext alloc]init]; 41 | context.type = MagneticTypeDemo; 42 | [dataArr addObject:context]; 43 | 44 | //demo2 45 | context = [[MagneticContext alloc]init]; 46 | context.type = MagneticTypeDemo2; 47 | context.json = @"TWO"; 48 | [dataArr addObject:context]; 49 | 50 | //demo3 51 | context = [[MagneticContext alloc]init]; 52 | context.type = MagneticTypeDemo3; 53 | context.json = @"THREE"; 54 | [dataArr addObject:context]; 55 | 56 | //demo4 57 | context = [[MagneticContext alloc]init]; 58 | context.type = MagneticTypeDemo4; 59 | [dataArr addObject:context]; 60 | 61 | //demo5 62 | context = [[MagneticContext alloc]init]; 63 | context.type = MagneticTypeDemo5; 64 | context.json = @"FIVE"; 65 | [dataArr addObject:context]; 66 | 67 | /** 68 | dataArr add more VC 69 | */ 70 | [self requestMagneticsDidSucceedWithMagneticsArray:dataArr]; 71 | } 72 | 73 | - (void)triggerRefreshAction { 74 | [super triggerRefreshAction]; 75 | NSMutableArray *dataArr = [NSMutableArray array]; 76 | //demo 77 | MagneticContext *context = [[MagneticContext alloc]init]; 78 | context.type = MagneticTypeDemo; 79 | [dataArr addObject:context]; 80 | 81 | //demo3 82 | context = [[MagneticContext alloc]init]; 83 | context.type = MagneticTypeDemo3; 84 | context.json = @"THREE"; 85 | [dataArr addObject:context]; 86 | 87 | //demo2 88 | context = [[MagneticContext alloc]init]; 89 | context.type = MagneticTypeDemo2; 90 | context.json = @"TWO"; 91 | [dataArr addObject:context]; 92 | 93 | /** 94 | dataArr add more VC 95 | */ 96 | [self requestMagneticsDidSucceedWithMagneticsArray:dataArr]; 97 | } 98 | 99 | //- (void)requestMoreData{ 100 | // MagneticContext *context = [[MagneticContext alloc]init]; 101 | // context.type = MagneticTypeDemo2; 102 | // context.json = @"FOUR"; 103 | // 104 | // //demo2 105 | // MagneticContext *context2 = [[MagneticContext alloc]init]; 106 | // context2.type = MagneticTypeDemo3; 107 | // context2.json = @"FIVE"; 108 | // [self requestMoreMagneticsDidSucceedWithMagneticsArray:@[context, context2]]; 109 | //} 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Controller/MagneticController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticController.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticsControllerProtocol.h" 10 | #import "MagneticContext.h" 11 | 12 | @class MagneticsController; 13 | 14 | @protocol MagneticControllerDelegate; 15 | 16 | @interface MagneticController : NSObject 17 | 18 | ///扩展控制器 19 | @property (nonatomic) MagneticController *extensionController; 20 | 21 | ///磁片数据源 22 | @property (nonatomic) MagneticContext *magneticContext; 23 | 24 | @property (nonatomic, weak) id delegate; 25 | 26 | ///磁片列表控制器 27 | @property (nonatomic, weak) MagneticsController *magneticsController; 28 | 29 | ///是否为扩展 30 | @property (nonatomic, assign) BOOL isExtension; 31 | 32 | ///折叠状态。默认为NO。 33 | @property (nonatomic, assign) BOOL isFold; 34 | 35 | ///是否完成准备,可渲染 36 | @property (nonatomic, assign) BOOL isPrepared; 37 | 38 | 39 | ///请求错误磁片数据 40 | - (void)requestErrorMagneticData; 41 | 42 | 43 | @end 44 | 45 | 46 | 47 | /** 48 | * 缓存参数,用于优化表视图性能 49 | */ 50 | @interface MagneticController (Cache) 51 | 52 | ///是否显示错误视图 53 | @property (nonatomic, assign) BOOL showMagneticError; 54 | 55 | ///是否显示头部视图 56 | @property (nonatomic, assign) BOOL showMagneticHeader; 57 | 58 | ///是否显示尾部视图 59 | @property (nonatomic, assign) BOOL showMagneticFooter; 60 | 61 | ///是否显示磁片头部间距 62 | @property (nonatomic, assign) BOOL showMagneticHeaderSpacing; 63 | 64 | ///是否显示磁片底部间距 65 | @property (nonatomic, assign) BOOL showMagneticSpacing; 66 | 67 | ///行数缓存 68 | @property (nonatomic, assign) NSInteger rowCountCache; 69 | 70 | ///扩展行数起始index 71 | @property (nonatomic, assign) NSInteger extensionRowIndex; 72 | 73 | ///行高缓存 74 | @property (nonatomic, copy) NSArray *rowHeightsCache; 75 | @end 76 | 77 | 78 | 79 | /** 80 | * 加载更多 81 | */ 82 | @interface MagneticController (RequestMore) 83 | 84 | ///是否可加载更多。默认为NO。开启后可响应-didTriggerRequestMoreDataActionInMagneticsController:协议。 85 | @property (nonatomic, assign) BOOL canRequestMoreData; 86 | 87 | @end 88 | 89 | 90 | 91 | @protocol MagneticControllerDelegate 92 | 93 | ///刷新指定类型的磁片 94 | - (void)refreshMagneticWithType:(MagneticType)type animation:(UITableViewRowAnimation)animation; 95 | ///刷新指定类型的磁片 96 | - (void)refreshMagneticWithType:(MagneticType)type; 97 | //刷新指定类型磁片的数据源 98 | - (void)refreshMagneticWithType:(MagneticType)type json:(id)json; 99 | 100 | /** 101 | * @brief 添加指定Section磁片 102 | * @param magneticType 磁片类型 103 | * @param magneticContext 刷新数据模型 104 | * @param magneticController 刷新controller 105 | * @param index 指定位置 106 | */ 107 | - (void)addSectionWithType:(MagneticType)magneticType 108 | withMagneticContext:(MagneticContext *)magneticContext 109 | withMagneticController:(MagneticController *)magneticController 110 | withIndex:(NSUInteger)index 111 | withAnimation:(UITableViewRowAnimation)animation; 112 | 113 | /** 114 | * @brief 删除指定Section磁片 115 | * @param magneticType 磁片类型 116 | * @param index 指定位置 117 | */ 118 | - (void)deleteSectionWithType:(MagneticType)magneticType 119 | withIndex:(NSUInteger)index 120 | withAnimation:(UITableViewRowAnimation)animation; 121 | 122 | @optional 123 | 124 | ///通用参数字典。用于请求参数、统计埋点等。 125 | - (NSDictionary *)generalParameters; 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Controller/MagneticsController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticsController.h 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/5/31. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticController.h" 10 | #import "MagneticErrorCell.h" 11 | #import "MagneticTableView.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | ///磁片列表刷新方式 16 | typedef NS_OPTIONS(NSUInteger, MagneticsRefreshType) { 17 | ///无刷新方式 18 | MagneticsRefreshTypeNone = 0, 19 | ///下拉刷新 20 | MagneticsRefreshTypePullToRefresh = 1 << 0, 21 | ///上拉加载更多 22 | MagneticsRefreshTypeInfiniteScrolling = 1 << 1, 23 | ///中心加载视图 24 | MagneticsRefreshTypeLoadingView = 1 << 2, 25 | }; 26 | 27 | ///磁片数据清除方式 28 | typedef NS_ENUM(NSUInteger, MagneticsClearType) { 29 | ///请求前清除 30 | MagneticsClearTypeBeforeRequest = 0, 31 | ///请求后清除 32 | MagneticsClearTypeAfterRequest = 1, 33 | }; 34 | 35 | @class MagneticController; 36 | 37 | @interface MagneticsController : UIViewController 38 | 39 | ///父视图控制器。内部监控页面显示隐藏,应使用业务子类。 40 | @property (nonatomic, weak) UIViewController *superViewController; 41 | 42 | ///磁片表视图 43 | @property (nonatomic, strong, readonly) MagneticTableView *tableView; 44 | 45 | ///磁片数据源 46 | @property (nonatomic, strong, readonly) NSMutableArray *magneticsArray; 47 | 48 | ///磁片控制器数据源 49 | @property (nonatomic, strong, readonly) NSMutableArray *magneticControllersArray; 50 | 51 | ///获取指定类型的磁片控制器 52 | - (NSArray *)queryMagneticControllersWithType:(MagneticType)type; 53 | 54 | ///滚动到指定类型的磁片 55 | - (void)scrollToMagneticType:(MagneticType)type animated:(BOOL)animated; 56 | @end 57 | 58 | 59 | @interface MagneticsController (Request) 60 | 61 | ///磁片列表刷新方式 62 | @property (nonatomic) MagneticsRefreshType refreshType; 63 | 64 | ///磁片数据清除方式 65 | @property (nonatomic) MagneticsClearType clearType; 66 | 67 | ///使用默认错误提示,default YES 68 | @property (nonatomic, assign) BOOL enableNetworkError; 69 | 70 | /// 当前磁片加载完成 71 | @property (nonatomic, assign) BOOL currentMagneticsLoadFinish; 72 | 73 | ///请求磁片列表(继承实现) 74 | - (void)requestMagnetics; 75 | ///加载更多数据。默认回调磁片-didTriggerRequestMoreDataActionInMagneticsController协议,可继承重写事件。 76 | - (void)requestMoreData; 77 | ///请求单磁片数据(继承实现) 78 | - (void)requestMagneticDataWithController:(MagneticController *)magneticController; 79 | 80 | ///磁片列表请求将开始 81 | - (void)requestMagneticsWillStart; 82 | ///磁片列表请求成功 83 | - (void)requestMagneticsDidSucceedWithMagneticsArray:(NSArray *)magneticsArray; 84 | ///磁片列表请求失败 85 | - (void)requestMagneticsDidFailWithError:(NSError *)error; 86 | 87 | ///加载更多磁片请求成功 88 | - (void)requestMoreMagneticsDidSucceedWithMagneticsArray:(NSArray *)magneticsArray; 89 | ///加载更多磁片失败 90 | - (void)requestMoreMagneticsDidFailWithError:(NSError *)error; 91 | 92 | ///磁片数据请求成功 93 | - (void)requestMagneticDataDidSucceedWithMagneticContext:(MagneticContext *)magneticContext; 94 | ///磁片列表请求失败 95 | - (void)requestMagneticDataDidFailWithMagneticContext:(MagneticContext *)magneticContext error:(NSError *)error; 96 | 97 | - (void)triggerRefreshAction; 98 | @end 99 | 100 | 101 | @interface MagneticsController (Bottom) 102 | 103 | ///显示表视图封底。默认为NO。若取值为YES且刷新方式不支持MagneticsRefreshTypeInfiniteScrolling,tableFooterView自动显示封底视图。 104 | @property (nonatomic, assign) BOOL enableTableBottomView; 105 | ///封底自定义视图。默认为nil,提示“没有更多了”+LOGO。 106 | @property (nonatomic) UIView *tableBottomCustomView; 107 | 108 | /* refresh */ 109 | @property (nonatomic) UIRefreshControl *refreshControl; 110 | 111 | /* more */ 112 | //@property (nonatomic) UIRefreshControl *moreControl; 113 | 114 | ///触发加载更多事件,启动加载动画 115 | - (void)triggerInfiniteScrollingAction; 116 | ///完成加载更多事件,停止加载动画 117 | - (void)finishInfiniteScrollingAction; 118 | ///完成所有数据加载,显示没有更多了封底图 119 | - (void)didFinishLoadAllData; 120 | 121 | @end 122 | 123 | 124 | @interface MagneticsController (BottomPrivate) 125 | 126 | - (void)refreshTableBottomView; //刷新封底视图 127 | 128 | @end 129 | 130 | NS_ASSUME_NONNULL_END 131 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic.xcodeproj/xcshareddata/xcschemes/ShelfMagnetic.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 63 | 65 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/WKWebView+AFNetworking.h: -------------------------------------------------------------------------------- 1 | // WkWebView+AFNetworking.h 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import 23 | 24 | #import 25 | 26 | #if TARGET_OS_IOS 27 | 28 | #import 29 | #import 30 | 31 | NS_ASSUME_NONNULL_BEGIN 32 | 33 | @class AFHTTPSessionManager; 34 | 35 | @interface WKWebView (AFNetworking) 36 | 37 | /** 38 | The session manager used to download all request 39 | */ 40 | @property (nonatomic, strong) AFHTTPSessionManager *sessionManager; 41 | 42 | /** 43 | Asynchronously loads the specified request. 44 | 45 | @param request A URL request identifying the location of the content to load. This must not be `nil`. 46 | @param navigation The WKNavigation object that containts information for tracking the loading progress of a webpage. This must not be `nil`. 47 | @param progress A progress object monitoring the current download progress. 48 | @param success A block object to be executed when the request finishes loading successfully. This block returns the HTML string to be loaded by the web view, and takes two arguments: the response, and the response string. 49 | @param failure A block object to be executed when the data task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error that occurred. 50 | */ 51 | - (void)loadRequest:(NSURLRequest *)request 52 | navigation:(WKNavigation * _Nonnull)navigation 53 | progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress 54 | success:(nullable NSString * (^)(NSHTTPURLResponse *response, NSString *HTML))success 55 | failure:(nullable void (^)(NSError *error))failure; 56 | 57 | /** 58 | Asynchronously loads the data associated with a particular request with a specified MIME type and text encoding. 59 | 60 | @param request A URL request identifying the location of the content to load. This must not be `nil`. 61 | @param navigation The WKNavigation object that containts information for tracking the loading progress of a webpage. This must not be `nil`. 62 | @param MIMEType The MIME type of the content. Defaults to the content type of the response if not specified. 63 | @param textEncodingName The IANA encoding name, as in `utf-8` or `utf-16`. Defaults to the response text encoding if not specified. 64 | @param progress A progress object monitoring the current download progress. 65 | @param success A block object to be executed when the request finishes loading successfully. This block returns the data to be loaded by the web view and takes two arguments: the response, and the downloaded data. 66 | @param failure A block object to be executed when the data task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error that occurred. 67 | */ 68 | - (void)loadRequest:(NSURLRequest *)request 69 | navigation:(WKNavigation * _Nonnull)navigation 70 | MIMEType:(nullable NSString *)MIMEType 71 | textEncodingName:(nullable NSString *)textEncodingName 72 | progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress 73 | success:(nullable NSData * (^)(NSHTTPURLResponse *response, NSData *data))success 74 | failure:(nullable void (^)(NSError *error))failure; 75 | 76 | @end 77 | 78 | NS_ASSUME_NONNULL_END 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/View/JEBaseEmptyView.m: -------------------------------------------------------------------------------- 1 | // 2 | // JEBaseEmptyView.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "JEBaseEmptyView.h" 10 | 11 | @interface JEBaseEmptyView () 12 | @property (nonatomic, strong) id target; 13 | @property (nonatomic) SEL selector; 14 | @property (nonatomic, strong) UIView *contentView; 15 | @property (nonatomic, strong, readwrite) UIImageView *errorIconView; 16 | @property (nonatomic, strong, readwrite) UILabel *errorDescLabel; 17 | @property (nonatomic, strong) UIButton *retryButton; 18 | @end 19 | 20 | @implementation JEBaseEmptyView 21 | 22 | - (instancetype)initWithFrame:(CGRect)frame { 23 | 24 | if (self = [super initWithFrame:frame]) { 25 | self.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 26 | self.backgroundColor = [UIColor whiteColor]; 27 | self.contentView = [[UIView alloc] initWithFrame:CGRectZero]; 28 | 29 | self.errorIconView = [[UIImageView alloc] initWithFrame:CGRectZero]; 30 | 31 | self.errorDescLabel = [[UILabel alloc] init]; 32 | self.errorDescLabel.font = [UIFont systemFontOfSize:13]; 33 | self.errorDescLabel.textColor = [UIColor grayColor]; 34 | self.errorDescLabel.textAlignment = NSTextAlignmentCenter; 35 | 36 | self.retryButton = [[UIButton alloc] init]; 37 | [self.retryButton setTitle:@"点击重试" forState:UIControlStateNormal]; 38 | [self.retryButton addTarget:self action:@selector(retryButtonActionClick:) forControlEvents:UIControlEventTouchUpInside]; 39 | [self.retryButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; 40 | self.retryButton.titleLabel.font = [UIFont systemFontOfSize:13]; 41 | self.retryButton.layer.cornerRadius = 16; 42 | self.retryButton.layer.borderColor = [UIColor grayColor].CGColor; 43 | self.retryButton.layer.borderWidth = 0.8; 44 | 45 | [self.contentView addSubview:self.errorIconView]; 46 | [self.contentView addSubview:self.errorDescLabel]; 47 | [self.contentView addSubview:self.retryButton]; 48 | [self addSubview:self.contentView]; 49 | } 50 | return self; 51 | } 52 | 53 | - (void)layoutSubviews { 54 | [super layoutSubviews]; 55 | CGFloat contentW = self.bounds.size.width; 56 | CGFloat contentH = self.errorIconView.image.size.height + 18 + (!self.retryButton.hidden ? 41 + 31 : 0); 57 | self.contentView.frame = CGRectMake((self.bounds.size.width - contentW)/2.0, (self.bounds.size.height - contentH)/2.0, contentW, contentH); 58 | if (self.errorIconView.image) { 59 | CGSize iconSize = self.errorIconView.image.size; 60 | self.errorIconView.frame = CGRectMake((contentW - iconSize.width)/2.0, 0, iconSize.width, iconSize.height); 61 | } 62 | self.errorDescLabel.frame = CGRectMake(0, self.errorIconView.frame.origin.y + self.errorIconView.frame.size.height, self.contentView.bounds.size.width, 18); 63 | self.retryButton.frame = CGRectMake((contentW - 85)/2.0, self.errorDescLabel.frame.origin.y + self.errorDescLabel.frame.size.height + 41, 85, 31); 64 | 65 | } 66 | 67 | - (void)setErrorType:(EErrorType)errorType { 68 | switch (errorType) { 69 | case EErrorTypeFailed: { 70 | self.retryButton.hidden = NO; 71 | self.errorIconView.image = [UIImage imageNamed:@"common_failed_icon"]; 72 | self.errorDescLabel.text = @"数据获取失败,请重试"; 73 | } 74 | break; 75 | case EErrorTypeNoData: { 76 | self.retryButton.hidden = YES; 77 | self.errorIconView.image = [UIImage imageNamed:@"common_failed_icon"]; 78 | self.errorDescLabel.text = @"暂无数据"; 79 | } 80 | break; 81 | case EErrorTypeNoNetwork: { 82 | self.retryButton.hidden = NO; 83 | self.errorIconView.image = [UIImage imageNamed:@"common_neterror_icon"]; 84 | self.errorDescLabel.text = @"数据获取失败,请重试"; 85 | } 86 | break; 87 | 88 | default: 89 | break; 90 | } 91 | [self setNeedsLayout]; 92 | } 93 | 94 | - (void)addTarget:(id)target retrySelector:(SEL)selector { 95 | _target = target; 96 | _selector = selector; 97 | } 98 | 99 | - (void)retryButtonActionClick:(UIButton *)sender { 100 | #pragma clang diagnostic push 101 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 102 | if ([_target respondsToSelector:_selector]) { 103 | [_target performSelector:_selector withObject:sender]; 104 | } 105 | #pragma clang diagnostic pop 106 | } 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Demo/MagneticDemo4Controller.m: -------------------------------------------------------------------------------- 1 | // 2 | // MagneticDemo4Controller.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jian Dong on 2021/2/27. 6 | // Copyright © 2021 Jenson. All rights reserved. 7 | // 8 | 9 | #import "MagneticDemo4Controller.h" 10 | 11 | @interface MagneticDemo4Controller() 12 | 13 | @end 14 | 15 | @implementation MagneticDemo4Controller 16 | 17 | ///完成初始化监听 18 | - (void)didFinishInitConfigurationInMagneticsController:(MagneticsController *)magneticsController{ 19 | self.collectionDelegate = self; 20 | self.isPrepared = YES; 21 | } 22 | #pragma mark - Magnetic Content 23 | 24 | /** 25 | * Magnetic Spacing 26 | * @brief 磁片头部间距 27 | */ 28 | 29 | ///磁片头部间距大小。默认为0.0,当高度为0.0时无间距(不占用cell)。 30 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticHeaderSpacingInTableView:(MagneticTableView *)tableView{ 31 | return 20; 32 | } 33 | 34 | ///磁片头部间距颜色。默认为透明。 35 | - (UIColor *)magneticsController:(MagneticsController *)magneticsController colorForMagneticHeaderSpacingInTableView:(MagneticTableView *)tableView{ 36 | return [UIColor lightTextColor]; 37 | } 38 | 39 | /** 40 | * Magnetic Header 41 | * @brief 磁片头部 42 | */ 43 | 44 | ///是否显示头部视图。默认为NO。 45 | - (BOOL)magneticsController:(MagneticsController *)magneticsController shouldShowMagneticHeaderInTableView:(MagneticTableView *)tableView{ 46 | return YES; 47 | } 48 | 49 | ///头部行高 50 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticHeaderInTableView:(MagneticTableView *)tableView{ 51 | return 10; 52 | } 53 | 54 | ///复用头部视图 55 | - (void)magneticsController:(MagneticsController *)magneticsController reuseCell:(UITableViewCell *)cell forMagneticHeaderInTableView:(MagneticTableView *)tableView{ 56 | UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 10)]; 57 | title.font = [UIFont boldSystemFontOfSize:10]; 58 | title.textColor = [UIColor blackColor]; 59 | title.text = @"FOUR"; 60 | title.textAlignment = NSTextAlignmentCenter; 61 | [cell.contentView addSubview:title]; 62 | } 63 | 64 | // 内容行数 65 | - (NSInteger)magneticsController:(MagneticsController *)magneticsController rowCountForMagneticContentInTableView:(MagneticTableView *)tableView{ 66 | return self.isPrepared ? 1 : 0; 67 | } 68 | 69 | // 内容行高 70 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController rowHeightForMagneticContentAtIndex:(NSInteger)index{ 71 | CGFloat itemW = (UIScreen.mainScreen.bounds.size.width - 24 - 15)/5; 72 | return (itemW/1.61+10) * 5; 73 | } 74 | 75 | - (CGFloat)magneticsController:(MagneticsController *)magneticsController heightForMagneticSpacingInTableView:(MagneticTableView *)tableView{ 76 | return 0; 77 | } 78 | 79 | ///内容视图Class。默认为UITableViewCell。 80 | - (Class)magneticsController:(MagneticsController *)magneticsController cellClassForMagneticContentAtIndex:(NSInteger)index{ 81 | return UITableViewCell.class; 82 | } 83 | 84 | #pragma mark - MagneticCollectionControllerProtocol 85 | ///数量 86 | - (NSInteger)collectionViewNumberOfItemsInCollectionView:(UICollectionView *)collectionView { 87 | return 20; 88 | } 89 | 90 | ///tableviewcell subview -> collectionView -> collectionViewCell 's size 91 | - (CGSize)collectionViewItemSizeInCollectionView:(UICollectionView *)collectionView sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ 92 | CGFloat itemW = (UIScreen.mainScreen.bounds.size.width - 24 - 15)/5; 93 | return CGSizeMake(itemW, itemW/1.61); 94 | } 95 | 96 | ///collection的高度 97 | - (CGFloat)collectionViewHeightInCollectionView:(UICollectionView *)collectionView { 98 | CGFloat itemW = (UIScreen.mainScreen.bounds.size.width - 24 - 15)/5; 99 | return (itemW/1.61+10) * 5; 100 | } 101 | 102 | ///元视图横向间距,default is 0 103 | - (CGFloat)collectionViewMinimumLineSpacingInCollectionView:(UICollectionView *)collectionView { 104 | return 5; 105 | } 106 | - (CGFloat)collectionViewMinimumInteritemSpacingInCollectionView:(UICollectionView *)collectionView;{ 107 | return 5; 108 | } 109 | - (UIEdgeInsets)collectionViewSectionInsetInCollectionView:(UICollectionView *)collectionView { 110 | return UIEdgeInsetsMake(5, 10, 0, 10); 111 | } 112 | 113 | ///组件内部collectionview reusecell 114 | - (void)magneticsController:(MagneticsController *)magneticsController collectionViewReuseCell:(UICollectionViewCell *)cell indexPath:(NSIndexPath *)indexPath { 115 | cell.backgroundColor = [UIColor blueColor]; 116 | 117 | } 118 | 119 | - (void)magneticsController:(MagneticsController *)magneticsController didSelectItemAtIndexPath:(NSIndexPath *)indexPath collectionView:(UICollectionView *)collectionView{ 120 | 121 | } 122 | 123 | @end 124 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.m: -------------------------------------------------------------------------------- 1 | // UIRefreshControl+AFNetworking.m 2 | // 3 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import "UIRefreshControl+AFNetworking.h" 24 | #import 25 | 26 | #if TARGET_OS_IOS 27 | 28 | #import "AFURLSessionManager.h" 29 | 30 | @interface AFRefreshControlNotificationObserver : NSObject 31 | @property (readonly, nonatomic, weak) UIRefreshControl *refreshControl; 32 | - (instancetype)initWithActivityRefreshControl:(UIRefreshControl *)refreshControl; 33 | 34 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task; 35 | 36 | @end 37 | 38 | @implementation UIRefreshControl (AFNetworking) 39 | 40 | - (AFRefreshControlNotificationObserver *)af_notificationObserver { 41 | AFRefreshControlNotificationObserver *notificationObserver = objc_getAssociatedObject(self, @selector(af_notificationObserver)); 42 | if (notificationObserver == nil) { 43 | notificationObserver = [[AFRefreshControlNotificationObserver alloc] initWithActivityRefreshControl:self]; 44 | objc_setAssociatedObject(self, @selector(af_notificationObserver), notificationObserver, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 45 | } 46 | return notificationObserver; 47 | } 48 | 49 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task { 50 | [[self af_notificationObserver] setRefreshingWithStateOfTask:task]; 51 | } 52 | 53 | @end 54 | 55 | @implementation AFRefreshControlNotificationObserver 56 | 57 | - (instancetype)initWithActivityRefreshControl:(UIRefreshControl *)refreshControl 58 | { 59 | self = [super init]; 60 | if (self) { 61 | _refreshControl = refreshControl; 62 | } 63 | return self; 64 | } 65 | 66 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task { 67 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 68 | 69 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil]; 70 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil]; 71 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil]; 72 | 73 | if (task) { 74 | UIRefreshControl *refreshControl = self.refreshControl; 75 | if (task.state == NSURLSessionTaskStateRunning) { 76 | [refreshControl beginRefreshing]; 77 | 78 | [notificationCenter addObserver:self selector:@selector(af_beginRefreshing) name:AFNetworkingTaskDidResumeNotification object:task]; 79 | [notificationCenter addObserver:self selector:@selector(af_endRefreshing) name:AFNetworkingTaskDidCompleteNotification object:task]; 80 | [notificationCenter addObserver:self selector:@selector(af_endRefreshing) name:AFNetworkingTaskDidSuspendNotification object:task]; 81 | } else { 82 | [refreshControl endRefreshing]; 83 | } 84 | } 85 | } 86 | 87 | #pragma mark - 88 | 89 | - (void)af_beginRefreshing { 90 | dispatch_async(dispatch_get_main_queue(), ^{ 91 | [self.refreshControl beginRefreshing]; 92 | }); 93 | } 94 | 95 | - (void)af_endRefreshing { 96 | dispatch_async(dispatch_get_main_queue(), ^{ 97 | [self.refreshControl endRefreshing]; 98 | }); 99 | } 100 | 101 | #pragma mark - 102 | 103 | - (void)dealloc { 104 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 105 | 106 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil]; 107 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil]; 108 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil]; 109 | } 110 | 111 | @end 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /ShelfMagnetic/ShelfMagnetic/Class/Request/JEHttpManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // JEHttpManager.m 3 | // ShelfMagnetic 4 | // 5 | // Created by Jenson on 2020/7/5. 6 | // Copyright © 2020 Jenson. All rights reserved. 7 | // 8 | 9 | #import "JEHttpManager.h" 10 | 11 | 12 | #ifdef DEBUG 13 | #define URLLog(FORMAT, ...) fprintf(stderr,"%s\n",[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]); 14 | #else 15 | #define URLLog(...) 16 | #endif 17 | 18 | @implementation JEHttpManager 19 | 20 | #pragma mark - request 21 | 22 | /// 请求 23 | /// @param requestType 请求类型 24 | /// @param url 全路径 25 | /// @param parameters 请求参数 26 | /// @param success 成功回调 27 | /// @param failure 失败回调 28 | + (void)requestType:(NSInteger)requestType 29 | requestUrl:(NSString *)url 30 | parameters:(NSDictionary *)parameters 31 | success:(void (^)(id responseObject))success 32 | failure:(void (^)(id error))failure{ 33 | 34 | } 35 | 36 | ///// GET 请求 37 | //- (NSURLSessionDataTask *)requestGet:(NSString *)url parameters:(NSDictionary *)parameters success:(void (^)(id))success failure:(void (^)(id))failure { 38 | // 39 | // if (!self.hasNetWork) { 40 | // if (failure) { 41 | // failure(nil); 42 | // } 43 | // return [NSURLSessionDataTask new]; 44 | // } 45 | // NSString * identifier = [[[NSUUID UUID] UUIDString] stringByAppendingFormat:@"&%@", [NSString stringWithFormat:@"%lld",[NSDate getDateTimeTOMilliSeconds]]]; 46 | // NSMutableDictionary *data = [NSMutableDictionary dictionaryWithDictionary:parameters]; 47 | // return [self.manager GET:url parameters:data headers:@{@"Client-Trace-Id":identifier} progress:^(NSProgress * _Nonnull downloadProgress) { 48 | // 49 | // } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { 50 | // [JEHttpManager logInfo:url para:parameters obj:responseObject error:nil Type:0]; 51 | // dispatch_async(dispatch_get_main_queue(), ^{ 52 | // 53 | // NSDictionary * dic; 54 | // if([responseObject isKindOfClass:[NSData class]]){ 55 | // dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:NULL]; 56 | // }else if([responseObject isKindOfClass:[NSDictionary class]]){ 57 | // dic = responseObject; 58 | // }else{ 59 | // failure(nil); 60 | // } 61 | // if (dic) { 62 | // // id datadic = [dic objectForKey:@"data"]; 63 | // int errnoCode = [[dic objectForKey:@"errno"] intValue]; 64 | // if (errnoCode == 0) { 65 | // if (success) { 66 | // success(dic); 67 | // } 68 | // } else { 69 | // NSString * errmsg = [NSString stringWithFormat:@"%@",[dic objectForKey:@"errmsg"]]; 70 | // if (errmsg && errmsg.length > 0) { 71 | // [JELoadingManager showString:errmsg]; 72 | // } 73 | // if (failure) { 74 | // failure(dic); 75 | // } 76 | // } 77 | // } 78 | // }); 79 | // } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { 80 | // [JEHttpManager logInfo:url para:parameters obj:nil error:error Type:0]; 81 | // dispatch_async(dispatch_get_main_queue(), ^{ 82 | // if (failure) { 83 | // failure(error); 84 | // } 85 | // }); 86 | // }]; 87 | //} 88 | 89 | 90 | + (void)logInfo:(NSString *)url para:(NSDictionary *)para obj:(id)obj error:(NSError *)error Type:(NSInteger)type { 91 | 92 | if (type == 1) { 93 | URLLog(@"\n--------POST"); 94 | } else { 95 | URLLog(@"\n--------GET"); 96 | } 97 | URLLog(@"url: %@", url); 98 | URLLog(@"para: %@", para); 99 | if (error) { 100 | URLLog(@"%@", [NSString stringWithFormat:@"\nerrorCode - %ld\ninfo - %@\n--------END\n", (long)error.code,error.description]); 101 | } else { 102 | URLLog(@"%@", [NSString stringWithFormat:@"responseObject = %@\n--------END\n", [self convertJSONWithDic:obj]]); 103 | } 104 | } 105 | 106 | //字典转JSON 107 | +(NSString *)convertJSONWithDic:(NSDictionary *)dic { 108 | NSError *err; 109 | if (dic) { 110 | NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&err]; 111 | if (err) { 112 | return @"字典转JSON出错"; 113 | } 114 | NSString *dicString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 115 | dicString = [dicString stringByReplacingOccurrencesOfString:@"\n" withString:@""]; 116 | dicString = [dicString stringByReplacingOccurrencesOfString:@"\t" withString:@""]; 117 | dicString = [dicString stringByReplacingOccurrencesOfString:@" " withString:@""]; 118 | dicString = [dicString stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"]; 119 | return dicString; 120 | } 121 | return @""; 122 | } 123 | @end 124 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.m: -------------------------------------------------------------------------------- 1 | // UIActivityIndicatorView+AFNetworking.m 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import "UIActivityIndicatorView+AFNetworking.h" 23 | #import 24 | 25 | #if TARGET_OS_IOS || TARGET_OS_TV 26 | 27 | #import "AFURLSessionManager.h" 28 | 29 | @interface AFActivityIndicatorViewNotificationObserver : NSObject 30 | @property (readonly, nonatomic, weak) UIActivityIndicatorView *activityIndicatorView; 31 | - (instancetype)initWithActivityIndicatorView:(UIActivityIndicatorView *)activityIndicatorView; 32 | 33 | - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task; 34 | 35 | @end 36 | 37 | @implementation UIActivityIndicatorView (AFNetworking) 38 | 39 | - (AFActivityIndicatorViewNotificationObserver *)af_notificationObserver { 40 | AFActivityIndicatorViewNotificationObserver *notificationObserver = objc_getAssociatedObject(self, @selector(af_notificationObserver)); 41 | if (notificationObserver == nil) { 42 | notificationObserver = [[AFActivityIndicatorViewNotificationObserver alloc] initWithActivityIndicatorView:self]; 43 | objc_setAssociatedObject(self, @selector(af_notificationObserver), notificationObserver, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 44 | } 45 | return notificationObserver; 46 | } 47 | 48 | - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task { 49 | [[self af_notificationObserver] setAnimatingWithStateOfTask:task]; 50 | } 51 | 52 | @end 53 | 54 | @implementation AFActivityIndicatorViewNotificationObserver 55 | 56 | - (instancetype)initWithActivityIndicatorView:(UIActivityIndicatorView *)activityIndicatorView 57 | { 58 | self = [super init]; 59 | if (self) { 60 | _activityIndicatorView = activityIndicatorView; 61 | } 62 | return self; 63 | } 64 | 65 | - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task { 66 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 67 | 68 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil]; 69 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil]; 70 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil]; 71 | 72 | if (task) { 73 | if (task.state != NSURLSessionTaskStateCompleted) { 74 | UIActivityIndicatorView *activityIndicatorView = self.activityIndicatorView; 75 | if (task.state == NSURLSessionTaskStateRunning) { 76 | [activityIndicatorView startAnimating]; 77 | } else { 78 | [activityIndicatorView stopAnimating]; 79 | } 80 | 81 | [notificationCenter addObserver:self selector:@selector(af_startAnimating) name:AFNetworkingTaskDidResumeNotification object:task]; 82 | [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidCompleteNotification object:task]; 83 | [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidSuspendNotification object:task]; 84 | } 85 | } 86 | } 87 | 88 | #pragma mark - 89 | 90 | - (void)af_startAnimating { 91 | dispatch_async(dispatch_get_main_queue(), ^{ 92 | [self.activityIndicatorView startAnimating]; 93 | }); 94 | } 95 | 96 | - (void)af_stopAnimating { 97 | dispatch_async(dispatch_get_main_queue(), ^{ 98 | [self.activityIndicatorView stopAnimating]; 99 | }); 100 | } 101 | 102 | #pragma mark - 103 | 104 | - (void)dealloc { 105 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 106 | 107 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil]; 108 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil]; 109 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil]; 110 | } 111 | 112 | @end 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /Shelfmagnetic.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod spec lint Shelfmagnetic.podspec' to ensure this is a 3 | # valid spec and to remove all comments including this before submitting the spec. 4 | # 5 | # To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html 6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/ 7 | # 8 | 9 | Pod::Spec.new do |spec| 10 | 11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 12 | # 13 | # These will help people to find your library, and whilst it 14 | # can feel like a chore to fill in it's definitely to your advantage. The 15 | # summary should be tweet-length, and the description more in depth. 16 | # 17 | 18 | spec.name = "Shelfmagnetic" 19 | spec.version = "0.1.0" 20 | spec.summary = "Shelfmagnetic" 21 | 22 | # This description is used to generate tags and improve search results. 23 | # * Think: What does it do? Why did you write it? What is the focus? 24 | # * Try to keep it short, snappy and to the point. 25 | # * Write the description between the DESC delimiters below. 26 | # * Finally, don't worry about the indent, CocoaPods strips it! 27 | spec.description = <<-DESC 28 | 磁片框架可以快速搭建程序,以注册继承的方式将VC随意组合,大大提升了开发效率和实现一些复杂的功能。 29 | DESC 30 | 31 | spec.homepage = "https://github.com/jenson21/shelfmagnetic" 32 | # spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" 33 | 34 | 35 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 36 | # 37 | # Licensing your code is important. See https://choosealicense.com for more info. 38 | # CocoaPods will detect a license file if there is a named LICENSE* 39 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'. 40 | # 41 | 42 | spec.license = "MIT" 43 | # spec.license = { :type => "MIT", :file => "FILE_LICENSE" } 44 | 45 | 46 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 47 | # 48 | # Specify the authors of the library, with email addresses. Email addresses 49 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also 50 | # accepts just a name if you'd rather not provide an email address. 51 | # 52 | # Specify a social_media_url where others can refer to, for example a twitter 53 | # profile URL. 54 | # 55 | 56 | spec.author = { "Jenson" => "jenson.pitaya@outlook.com" } 57 | # Or just: spec.author = "Jenson" 58 | # spec.authors = { "Jenson" => "jenson.pitaya@outlook.com" } 59 | # spec.social_media_url = "https://twitter.com/Jenson" 60 | 61 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 62 | # 63 | # If this Pod runs only on iOS or OS X, then specify the platform and 64 | # the deployment target. You can optionally include the target after the platform. 65 | # 66 | 67 | # spec.platform = :ios 68 | spec.platform = :ios, "10.0" 69 | 70 | # When using multiple platforms 71 | # spec.ios.deployment_target = "5.0" 72 | # spec.osx.deployment_target = "10.7" 73 | # spec.watchos.deployment_target = "2.0" 74 | # spec.tvos.deployment_target = "10.0" 75 | 76 | 77 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 78 | # 79 | # Specify the location from where the source should be retrieved. 80 | # Supports git, hg, bzr, svn and HTTP. 81 | # 82 | 83 | spec.source = { :git => "https://github.com/jenson21/shelfmagnetic.git", :tag => "#{spec.version}" } 84 | 85 | 86 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 87 | # 88 | # CocoaPods is smart about how it includes source code. For source files 89 | # giving a folder will include any swift, h, m, mm, c & cpp files. 90 | # For header files it will include any header in the folder. 91 | # Not including the public_header_files will make all headers public. 92 | # 93 | 94 | spec.source_files = "ShelfMagnetic", "ShelfMagnetic/ShelfMagnetic/Class/**/*.{h,m}" 95 | 96 | #spec.exclude_files = "ShelfMagnetic/Exclude" 97 | 98 | #spec.public_header_files = "Classes/**/*.h" 99 | 100 | 101 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 102 | # 103 | # A list of resources included with the Pod. These are copied into the 104 | # target bundle with a build phase script. Anything else will be cleaned. 105 | # You can preserve files from being cleaned, please don't preserve 106 | # non-essential files like tests, examples and documentation. 107 | # 108 | 109 | # spec.resource = "icon.png" 110 | # spec.resources = "Resources/*.png" 111 | 112 | # spec.preserve_paths = "FilesToSave", "MoreFilesToSave" 113 | 114 | 115 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 116 | # 117 | # Link your library with frameworks, or libraries. Libraries do not include 118 | # the lib prefix of their name. 119 | # 120 | 121 | # spec.framework = "SomeFramework" 122 | spec.frameworks = "UIKit","Foundation" 123 | 124 | # spec.library = "iconv" 125 | # spec.libraries = "iconv", "xml2" 126 | 127 | 128 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 129 | # 130 | # If your library depends on compiler flags you can set them in the xcconfig hash 131 | # where they will only apply to your library. If you depend on other Podspecs 132 | # you can include multiple dependencies to ensure it works. 133 | 134 | spec.requires_arc = true 135 | 136 | # spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" } 137 | spec.dependency "AFNetworking", "~> 4.0.1" 138 | 139 | end 140 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.m: -------------------------------------------------------------------------------- 1 | // UIProgressView+AFNetworking.m 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import "UIProgressView+AFNetworking.h" 23 | 24 | #import 25 | 26 | #if TARGET_OS_IOS || TARGET_OS_TV 27 | 28 | #import "AFURLSessionManager.h" 29 | 30 | static void * AFTaskCountOfBytesSentContext = &AFTaskCountOfBytesSentContext; 31 | static void * AFTaskCountOfBytesReceivedContext = &AFTaskCountOfBytesReceivedContext; 32 | 33 | #pragma mark - 34 | 35 | @implementation UIProgressView (AFNetworking) 36 | 37 | - (BOOL)af_uploadProgressAnimated { 38 | return [(NSNumber *)objc_getAssociatedObject(self, @selector(af_uploadProgressAnimated)) boolValue]; 39 | } 40 | 41 | - (void)af_setUploadProgressAnimated:(BOOL)animated { 42 | objc_setAssociatedObject(self, @selector(af_uploadProgressAnimated), @(animated), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 43 | } 44 | 45 | - (BOOL)af_downloadProgressAnimated { 46 | return [(NSNumber *)objc_getAssociatedObject(self, @selector(af_downloadProgressAnimated)) boolValue]; 47 | } 48 | 49 | - (void)af_setDownloadProgressAnimated:(BOOL)animated { 50 | objc_setAssociatedObject(self, @selector(af_downloadProgressAnimated), @(animated), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 51 | } 52 | 53 | #pragma mark - 54 | 55 | - (void)setProgressWithUploadProgressOfTask:(NSURLSessionUploadTask *)task 56 | animated:(BOOL)animated 57 | { 58 | if (task.state == NSURLSessionTaskStateCompleted) { 59 | return; 60 | } 61 | 62 | [task addObserver:self forKeyPath:@"state" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesSentContext]; 63 | [task addObserver:self forKeyPath:@"countOfBytesSent" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesSentContext]; 64 | 65 | [self af_setUploadProgressAnimated:animated]; 66 | } 67 | 68 | - (void)setProgressWithDownloadProgressOfTask:(NSURLSessionDownloadTask *)task 69 | animated:(BOOL)animated 70 | { 71 | if (task.state == NSURLSessionTaskStateCompleted) { 72 | return; 73 | } 74 | 75 | [task addObserver:self forKeyPath:@"state" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesReceivedContext]; 76 | [task addObserver:self forKeyPath:@"countOfBytesReceived" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesReceivedContext]; 77 | 78 | [self af_setDownloadProgressAnimated:animated]; 79 | } 80 | 81 | #pragma mark - NSKeyValueObserving 82 | 83 | - (void)observeValueForKeyPath:(NSString *)keyPath 84 | ofObject:(id)object 85 | change:(__unused NSDictionary *)change 86 | context:(void *)context 87 | { 88 | if (context == AFTaskCountOfBytesSentContext || context == AFTaskCountOfBytesReceivedContext) { 89 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesSent))]) { 90 | if ([object countOfBytesExpectedToSend] > 0) { 91 | dispatch_async(dispatch_get_main_queue(), ^{ 92 | [self setProgress:[object countOfBytesSent] / ([object countOfBytesExpectedToSend] * 1.0f) animated:self.af_uploadProgressAnimated]; 93 | }); 94 | } 95 | } 96 | 97 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesReceived))]) { 98 | if ([object countOfBytesExpectedToReceive] > 0) { 99 | dispatch_async(dispatch_get_main_queue(), ^{ 100 | [self setProgress:[object countOfBytesReceived] / ([object countOfBytesExpectedToReceive] * 1.0f) animated:self.af_downloadProgressAnimated]; 101 | }); 102 | } 103 | } 104 | 105 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(state))]) { 106 | if ([(NSURLSessionTask *)object state] == NSURLSessionTaskStateCompleted) { 107 | @try { 108 | [object removeObserver:self forKeyPath:NSStringFromSelector(@selector(state))]; 109 | 110 | if (context == AFTaskCountOfBytesSentContext) { 111 | [object removeObserver:self forKeyPath:NSStringFromSelector(@selector(countOfBytesSent))]; 112 | } 113 | 114 | if (context == AFTaskCountOfBytesReceivedContext) { 115 | [object removeObserver:self forKeyPath:NSStringFromSelector(@selector(countOfBytesReceived))]; 116 | } 117 | } 118 | @catch (NSException * __unused exception) {} 119 | } 120 | } 121 | } 122 | } 123 | 124 | @end 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.h: -------------------------------------------------------------------------------- 1 | // AFNetworkActivityIndicatorManager.h 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import 23 | 24 | #import 25 | 26 | #if TARGET_OS_IOS 27 | 28 | #import 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | /** 33 | `AFNetworkActivityIndicatorManager` manages the state of the network activity indicator in the status bar. When enabled, it will listen for notifications indicating that a session task has started or finished, and start or stop animating the indicator accordingly. The number of active requests is incremented and decremented much like a stack or a semaphore, and the activity indicator will animate so long as that number is greater than zero. 34 | 35 | You should enable the shared instance of `AFNetworkActivityIndicatorManager` when your application finishes launching. In `AppDelegate application:didFinishLaunchingWithOptions:` you can do so with the following code: 36 | 37 | [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; 38 | 39 | By setting `enabled` to `YES` for `sharedManager`, the network activity indicator will show and hide automatically as requests start and finish. You should not ever need to call `incrementActivityCount` or `decrementActivityCount` yourself. 40 | 41 | See the Apple Human Interface Guidelines section about the Network Activity Indicator for more information: 42 | http://developer.apple.com/library/iOS/#documentation/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW44 43 | */ 44 | NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead.") 45 | @interface AFNetworkActivityIndicatorManager : NSObject 46 | 47 | /** 48 | A Boolean value indicating whether the manager is enabled. 49 | 50 | If YES, the manager will change status bar network activity indicator according to network operation notifications it receives. The default value is NO. 51 | */ 52 | @property (nonatomic, assign, getter = isEnabled) BOOL enabled; 53 | 54 | /** 55 | A Boolean value indicating whether the network activity indicator manager is currently active. 56 | */ 57 | @property (readonly, nonatomic, assign, getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible; 58 | 59 | /** 60 | A time interval indicating the minimum duration of networking activity that should occur before the activity indicator is displayed. The default value 1 second. If the network activity indicator should be displayed immediately when network activity occurs, this value should be set to 0 seconds. 61 | 62 | Apple's HIG describes the following: 63 | 64 | > Display the network activity indicator to provide feedback when your app accesses the network for more than a couple of seconds. If the operation finishes sooner than that, you don’t have to show the network activity indicator, because the indicator is likely to disappear before users notice its presence. 65 | 66 | */ 67 | @property (nonatomic, assign) NSTimeInterval activationDelay; 68 | 69 | /** 70 | A time interval indicating the duration of time of no networking activity required before the activity indicator is disabled. This allows for continuous display of the network activity indicator across multiple requests. The default value is 0.17 seconds. 71 | */ 72 | 73 | @property (nonatomic, assign) NSTimeInterval completionDelay; 74 | 75 | /** 76 | Returns the shared network activity indicator manager object for the system. 77 | 78 | @return The systemwide network activity indicator manager. 79 | */ 80 | + (instancetype)sharedManager; 81 | 82 | /** 83 | Increments the number of active network requests. If this number was zero before incrementing, this will start animating the status bar network activity indicator. 84 | */ 85 | - (void)incrementActivityCount; 86 | 87 | /** 88 | Decrements the number of active network requests. If this number becomes zero after decrementing, this will stop animating the status bar network activity indicator. 89 | */ 90 | - (void)decrementActivityCount; 91 | 92 | /** 93 | Set the a custom method to be executed when the network activity indicator manager should be hidden/shown. By default, this is null, and the UIApplication Network Activity Indicator will be managed automatically. If this block is set, it is the responsiblity of the caller to manager the network activity indicator going forward. 94 | 95 | @param block A block to be executed when the network activity indicator status changes. 96 | */ 97 | - (void)setNetworkingActivityActionWithBlock:(nullable void (^)(BOOL networkActivityIndicatorVisible))block; 98 | 99 | @end 100 | 101 | NS_ASSUME_NONNULL_END 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/UIImageView+AFNetworking.h: -------------------------------------------------------------------------------- 1 | // UIImageView+AFNetworking.h 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import 23 | 24 | #import 25 | 26 | #if TARGET_OS_IOS || TARGET_OS_TV 27 | 28 | #import 29 | 30 | NS_ASSUME_NONNULL_BEGIN 31 | 32 | @class AFImageDownloader; 33 | 34 | /** 35 | This category adds methods to the UIKit framework's `UIImageView` class. The methods in this category provide support for loading remote images asynchronously from a URL. 36 | */ 37 | @interface UIImageView (AFNetworking) 38 | 39 | ///------------------------------------ 40 | /// @name Accessing the Image Downloader 41 | ///------------------------------------ 42 | 43 | /** 44 | Set the shared image downloader used to download images. 45 | 46 | @param imageDownloader The shared image downloader used to download images. 47 | */ 48 | + (void)setSharedImageDownloader:(AFImageDownloader *)imageDownloader; 49 | 50 | /** 51 | The shared image downloader used to download images. 52 | */ 53 | + (AFImageDownloader *)sharedImageDownloader; 54 | 55 | ///-------------------- 56 | /// @name Setting Image 57 | ///-------------------- 58 | 59 | /** 60 | Asynchronously downloads an image from the specified URL, and sets it once the request is finished. Any previous image request for the receiver will be cancelled. 61 | 62 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished. 63 | 64 | By default, URL requests have a `Accept` header field value of "image / *", a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:` 65 | 66 | @param url The URL used for the image request. 67 | */ 68 | - (void)setImageWithURL:(NSURL *)url; 69 | 70 | /** 71 | Asynchronously downloads an image from the specified URL, and sets it once the request is finished. Any previous image request for the receiver will be cancelled. 72 | 73 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished. 74 | 75 | By default, URL requests have a `Accept` header field value of "image / *", a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:` 76 | 77 | @param url The URL used for the image request. 78 | @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes. 79 | */ 80 | - (void)setImageWithURL:(NSURL *)url 81 | placeholderImage:(nullable UIImage *)placeholderImage; 82 | 83 | /** 84 | Asynchronously downloads an image from the specified URL request, and sets it once the request is finished. Any previous image request for the receiver will be cancelled. 85 | 86 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished. 87 | 88 | If a success block is specified, it is the responsibility of the block to set the image of the image view before returning. If no success block is specified, the default behavior of setting the image with `self.image = image` is applied. 89 | 90 | @param urlRequest The URL request used for the image request. 91 | @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes. 92 | @param success A block to be executed when the image data task finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the response parameter will be `nil`. 93 | @param failure A block object to be executed when the image data task finishes unsuccessfully, or that finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error object describing the network or parsing error that occurred. 94 | */ 95 | - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest 96 | placeholderImage:(nullable UIImage *)placeholderImage 97 | success:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, UIImage *image))success 98 | failure:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, NSError *error))failure; 99 | 100 | /** 101 | Cancels any executing image operation for the receiver, if one exists. 102 | */ 103 | - (void)cancelImageDownloadTask; 104 | 105 | @end 106 | 107 | NS_ASSUME_NONNULL_END 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/AFNetworking/AFSecurityPolicy.h: -------------------------------------------------------------------------------- 1 | // AFSecurityPolicy.h 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import 23 | #import 24 | 25 | typedef NS_ENUM(NSUInteger, AFSSLPinningMode) { 26 | AFSSLPinningModeNone, 27 | AFSSLPinningModePublicKey, 28 | AFSSLPinningModeCertificate, 29 | }; 30 | 31 | /** 32 | `AFSecurityPolicy` evaluates server trust against pinned X.509 certificates and public keys over secure connections. 33 | 34 | Adding pinned SSL certificates to your app helps prevent man-in-the-middle attacks and other vulnerabilities. Applications dealing with sensitive customer data or financial information are strongly encouraged to route all communication over an HTTPS connection with SSL pinning configured and enabled. 35 | */ 36 | 37 | NS_ASSUME_NONNULL_BEGIN 38 | 39 | @interface AFSecurityPolicy : NSObject 40 | 41 | /** 42 | The criteria by which server trust should be evaluated against the pinned SSL certificates. Defaults to `AFSSLPinningModeNone`. 43 | */ 44 | @property (readonly, nonatomic, assign) AFSSLPinningMode SSLPinningMode; 45 | 46 | /** 47 | The certificates used to evaluate server trust according to the SSL pinning mode. 48 | 49 | Note that if pinning is enabled, `evaluateServerTrust:forDomain:` will return true if any pinned certificate matches. 50 | 51 | @see policyWithPinningMode:withPinnedCertificates: 52 | */ 53 | @property (nonatomic, strong, nullable) NSSet *pinnedCertificates; 54 | 55 | /** 56 | Whether or not to trust servers with an invalid or expired SSL certificates. Defaults to `NO`. 57 | */ 58 | @property (nonatomic, assign) BOOL allowInvalidCertificates; 59 | 60 | /** 61 | Whether or not to validate the domain name in the certificate's CN field. Defaults to `YES`. 62 | */ 63 | @property (nonatomic, assign) BOOL validatesDomainName; 64 | 65 | ///----------------------------------------- 66 | /// @name Getting Certificates from the Bundle 67 | ///----------------------------------------- 68 | 69 | /** 70 | Returns any certificates included in the bundle. If you are using AFNetworking as an embedded framework, you must use this method to find the certificates you have included in your app bundle, and use them when creating your security policy by calling `policyWithPinningMode:withPinnedCertificates`. 71 | 72 | @return The certificates included in the given bundle. 73 | */ 74 | + (NSSet *)certificatesInBundle:(NSBundle *)bundle; 75 | 76 | ///----------------------------------------- 77 | /// @name Getting Specific Security Policies 78 | ///----------------------------------------- 79 | 80 | /** 81 | Returns the shared default security policy, which does not allow invalid certificates, validates domain name, and does not validate against pinned certificates or public keys. 82 | 83 | @return The default security policy. 84 | */ 85 | + (instancetype)defaultPolicy; 86 | 87 | ///--------------------- 88 | /// @name Initialization 89 | ///--------------------- 90 | 91 | /** 92 | Creates and returns a security policy with the specified pinning mode. 93 | 94 | Certificates with the `.cer` extension found in the main bundle will be pinned. If you want more control over which certificates are pinned, please use `policyWithPinningMode:withPinnedCertificates:` instead. 95 | 96 | @param pinningMode The SSL pinning mode. 97 | 98 | @return A new security policy. 99 | 100 | @see -policyWithPinningMode:withPinnedCertificates: 101 | */ 102 | + (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode; 103 | 104 | /** 105 | Creates and returns a security policy with the specified pinning mode. 106 | 107 | @param pinningMode The SSL pinning mode. 108 | @param pinnedCertificates The certificates to pin against. 109 | 110 | @return A new security policy. 111 | 112 | @see +certificatesInBundle: 113 | @see -pinnedCertificates 114 | */ 115 | + (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode withPinnedCertificates:(NSSet *)pinnedCertificates; 116 | 117 | ///------------------------------ 118 | /// @name Evaluating Server Trust 119 | ///------------------------------ 120 | 121 | /** 122 | Whether or not the specified server trust should be accepted, based on the security policy. 123 | 124 | This method should be used when responding to an authentication challenge from a server. 125 | 126 | @param serverTrust The X.509 certificate trust of the server. 127 | @param domain The domain of serverTrust. If `nil`, the domain will not be validated. 128 | 129 | @return Whether or not to trust the server. 130 | */ 131 | - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust 132 | forDomain:(nullable NSString *)domain; 133 | 134 | @end 135 | 136 | NS_ASSUME_NONNULL_END 137 | 138 | ///---------------- 139 | /// @name Constants 140 | ///---------------- 141 | 142 | /** 143 | ## SSL Pinning Modes 144 | 145 | The following constants are provided by `AFSSLPinningMode` as possible SSL pinning modes. 146 | 147 | enum { 148 | AFSSLPinningModeNone, 149 | AFSSLPinningModePublicKey, 150 | AFSSLPinningModeCertificate, 151 | } 152 | 153 | `AFSSLPinningModeNone` 154 | Do not used pinned certificates to validate servers. 155 | 156 | `AFSSLPinningModePublicKey` 157 | Validate host certificates against public keys of pinned certificates. 158 | 159 | `AFSSLPinningModeCertificate` 160 | Validate host certificates against pinned certificates. 161 | */ 162 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/UIImageView+AFNetworking.m: -------------------------------------------------------------------------------- 1 | // UIImageView+AFNetworking.m 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import "UIImageView+AFNetworking.h" 23 | 24 | #import 25 | 26 | #if TARGET_OS_IOS || TARGET_OS_TV 27 | 28 | #import "AFImageDownloader.h" 29 | 30 | @interface UIImageView (_AFNetworking) 31 | @property (readwrite, nonatomic, strong, setter = af_setActiveImageDownloadReceipt:) AFImageDownloadReceipt *af_activeImageDownloadReceipt; 32 | @end 33 | 34 | @implementation UIImageView (_AFNetworking) 35 | 36 | - (AFImageDownloadReceipt *)af_activeImageDownloadReceipt { 37 | return (AFImageDownloadReceipt *)objc_getAssociatedObject(self, @selector(af_activeImageDownloadReceipt)); 38 | } 39 | 40 | - (void)af_setActiveImageDownloadReceipt:(AFImageDownloadReceipt *)imageDownloadReceipt { 41 | objc_setAssociatedObject(self, @selector(af_activeImageDownloadReceipt), imageDownloadReceipt, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 42 | } 43 | 44 | @end 45 | 46 | #pragma mark - 47 | 48 | @implementation UIImageView (AFNetworking) 49 | 50 | + (AFImageDownloader *)sharedImageDownloader { 51 | return objc_getAssociatedObject([UIImageView class], @selector(sharedImageDownloader)) ?: [AFImageDownloader defaultInstance]; 52 | } 53 | 54 | + (void)setSharedImageDownloader:(AFImageDownloader *)imageDownloader { 55 | objc_setAssociatedObject([UIImageView class], @selector(sharedImageDownloader), imageDownloader, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 56 | } 57 | 58 | #pragma mark - 59 | 60 | - (void)setImageWithURL:(NSURL *)url { 61 | [self setImageWithURL:url placeholderImage:nil]; 62 | } 63 | 64 | - (void)setImageWithURL:(NSURL *)url 65 | placeholderImage:(UIImage *)placeholderImage 66 | { 67 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 68 | [request addValue:@"image/*" forHTTPHeaderField:@"Accept"]; 69 | 70 | [self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil]; 71 | } 72 | 73 | - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest 74 | placeholderImage:(UIImage *)placeholderImage 75 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, UIImage *image))success 76 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, NSError *error))failure 77 | { 78 | if ([urlRequest URL] == nil) { 79 | self.image = placeholderImage; 80 | if (failure) { 81 | NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadURL userInfo:nil]; 82 | failure(urlRequest, nil, error); 83 | } 84 | return; 85 | } 86 | 87 | if ([self isActiveTaskURLEqualToURLRequest:urlRequest]) { 88 | return; 89 | } 90 | 91 | [self cancelImageDownloadTask]; 92 | 93 | AFImageDownloader *downloader = [[self class] sharedImageDownloader]; 94 | id imageCache = downloader.imageCache; 95 | 96 | //Use the image from the image cache if it exists 97 | UIImage *cachedImage = [imageCache imageforRequest:urlRequest withAdditionalIdentifier:nil]; 98 | if (cachedImage) { 99 | if (success) { 100 | success(urlRequest, nil, cachedImage); 101 | } else { 102 | self.image = cachedImage; 103 | } 104 | [self clearActiveDownloadInformation]; 105 | } else { 106 | if (placeholderImage) { 107 | self.image = placeholderImage; 108 | } 109 | 110 | __weak __typeof(self)weakSelf = self; 111 | NSUUID *downloadID = [NSUUID UUID]; 112 | AFImageDownloadReceipt *receipt; 113 | receipt = [downloader 114 | downloadImageForURLRequest:urlRequest 115 | withReceiptID:downloadID 116 | success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull responseObject) { 117 | __strong __typeof(weakSelf)strongSelf = weakSelf; 118 | if ([strongSelf.af_activeImageDownloadReceipt.receiptID isEqual:downloadID]) { 119 | if (success) { 120 | success(request, response, responseObject); 121 | } else if (responseObject) { 122 | strongSelf.image = responseObject; 123 | } 124 | [strongSelf clearActiveDownloadInformation]; 125 | } 126 | 127 | } 128 | failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) { 129 | __strong __typeof(weakSelf)strongSelf = weakSelf; 130 | if ([strongSelf.af_activeImageDownloadReceipt.receiptID isEqual:downloadID]) { 131 | if (failure) { 132 | failure(request, response, error); 133 | } 134 | [strongSelf clearActiveDownloadInformation]; 135 | } 136 | }]; 137 | 138 | self.af_activeImageDownloadReceipt = receipt; 139 | } 140 | } 141 | 142 | - (void)cancelImageDownloadTask { 143 | if (self.af_activeImageDownloadReceipt != nil) { 144 | [[self.class sharedImageDownloader] cancelTaskForImageDownloadReceipt:self.af_activeImageDownloadReceipt]; 145 | [self clearActiveDownloadInformation]; 146 | } 147 | } 148 | 149 | - (void)clearActiveDownloadInformation { 150 | self.af_activeImageDownloadReceipt = nil; 151 | } 152 | 153 | - (BOOL)isActiveTaskURLEqualToURLRequest:(NSURLRequest *)urlRequest { 154 | return [self.af_activeImageDownloadReceipt.task.originalRequest.URL.absoluteString isEqualToString:urlRequest.URL.absoluteString]; 155 | } 156 | 157 | @end 158 | 159 | #endif 160 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/AFAutoPurgingImageCache.h: -------------------------------------------------------------------------------- 1 | // AFAutoPurgingImageCache.h 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import 23 | #import 24 | 25 | #if TARGET_OS_IOS || TARGET_OS_TV 26 | #import 27 | 28 | NS_ASSUME_NONNULL_BEGIN 29 | 30 | /** 31 | The `AFImageCache` protocol defines a set of APIs for adding, removing and fetching images from a cache synchronously. 32 | */ 33 | @protocol AFImageCache 34 | 35 | /** 36 | Adds the image to the cache with the given identifier. 37 | 38 | @param image The image to cache. 39 | @param identifier The unique identifier for the image in the cache. 40 | */ 41 | - (void)addImage:(UIImage *)image withIdentifier:(NSString *)identifier; 42 | 43 | /** 44 | Removes the image from the cache matching the given identifier. 45 | 46 | @param identifier The unique identifier for the image in the cache. 47 | 48 | @return A BOOL indicating whether or not the image was removed from the cache. 49 | */ 50 | - (BOOL)removeImageWithIdentifier:(NSString *)identifier; 51 | 52 | /** 53 | Removes all images from the cache. 54 | 55 | @return A BOOL indicating whether or not all images were removed from the cache. 56 | */ 57 | - (BOOL)removeAllImages; 58 | 59 | /** 60 | Returns the image in the cache associated with the given identifier. 61 | 62 | @param identifier The unique identifier for the image in the cache. 63 | 64 | @return An image for the matching identifier, or nil. 65 | */ 66 | - (nullable UIImage *)imageWithIdentifier:(NSString *)identifier; 67 | @end 68 | 69 | 70 | /** 71 | The `ImageRequestCache` protocol extends the `ImageCache` protocol by adding methods for adding, removing and fetching images from a cache given an `NSURLRequest` and additional identifier. 72 | */ 73 | @protocol AFImageRequestCache 74 | 75 | /** 76 | Asks if the image should be cached using an identifier created from the request and additional identifier. 77 | 78 | @param image The image to be cached. 79 | @param request The unique URL request identifing the image asset. 80 | @param identifier The additional identifier to apply to the URL request to identify the image. 81 | 82 | @return A BOOL indicating whether or not the image should be added to the cache. YES will cache, NO will prevent caching. 83 | */ 84 | - (BOOL)shouldCacheImage:(UIImage *)image forRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier; 85 | 86 | /** 87 | Adds the image to the cache using an identifier created from the request and additional identifier. 88 | 89 | @param image The image to cache. 90 | @param request The unique URL request identifing the image asset. 91 | @param identifier The additional identifier to apply to the URL request to identify the image. 92 | */ 93 | - (void)addImage:(UIImage *)image forRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier; 94 | 95 | /** 96 | Removes the image from the cache using an identifier created from the request and additional identifier. 97 | 98 | @param request The unique URL request identifing the image asset. 99 | @param identifier The additional identifier to apply to the URL request to identify the image. 100 | 101 | @return A BOOL indicating whether or not all images were removed from the cache. 102 | */ 103 | - (BOOL)removeImageforRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier; 104 | 105 | /** 106 | Returns the image from the cache associated with an identifier created from the request and additional identifier. 107 | 108 | @param request The unique URL request identifing the image asset. 109 | @param identifier The additional identifier to apply to the URL request to identify the image. 110 | 111 | @return An image for the matching request and identifier, or nil. 112 | */ 113 | - (nullable UIImage *)imageforRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier; 114 | 115 | @end 116 | 117 | /** 118 | The `AutoPurgingImageCache` in an in-memory image cache used to store images up to a given memory capacity. When the memory capacity is reached, the image cache is sorted by last access date, then the oldest image is continuously purged until the preferred memory usage after purge is met. Each time an image is accessed through the cache, the internal access date of the image is updated. 119 | */ 120 | @interface AFAutoPurgingImageCache : NSObject 121 | 122 | /** 123 | The total memory capacity of the cache in bytes. 124 | */ 125 | @property (nonatomic, assign) UInt64 memoryCapacity; 126 | 127 | /** 128 | The preferred memory usage after purge in bytes. During a purge, images will be purged until the memory capacity drops below this limit. 129 | */ 130 | @property (nonatomic, assign) UInt64 preferredMemoryUsageAfterPurge; 131 | 132 | /** 133 | The current total memory usage in bytes of all images stored within the cache. 134 | */ 135 | @property (nonatomic, assign, readonly) UInt64 memoryUsage; 136 | 137 | /** 138 | Initialies the `AutoPurgingImageCache` instance with default values for memory capacity and preferred memory usage after purge limit. `memoryCapcity` defaults to `100 MB`. `preferredMemoryUsageAfterPurge` defaults to `60 MB`. 139 | 140 | @return The new `AutoPurgingImageCache` instance. 141 | */ 142 | - (instancetype)init; 143 | 144 | /** 145 | Initialies the `AutoPurgingImageCache` instance with the given memory capacity and preferred memory usage 146 | after purge limit. 147 | 148 | @param memoryCapacity The total memory capacity of the cache in bytes. 149 | @param preferredMemoryCapacity The preferred memory usage after purge in bytes. 150 | 151 | @return The new `AutoPurgingImageCache` instance. 152 | */ 153 | - (instancetype)initWithMemoryCapacity:(UInt64)memoryCapacity preferredMemoryCapacity:(UInt64)preferredMemoryCapacity; 154 | 155 | @end 156 | 157 | NS_ASSUME_NONNULL_END 158 | 159 | #endif 160 | 161 | -------------------------------------------------------------------------------- /ShelfMagnetic/Pods/AFNetworking/UIKit+AFNetworking/WKWebView+AFNetworking.m: -------------------------------------------------------------------------------- 1 | // WkWebView+AFNetworking.m 2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #import "WKWebView+AFNetworking.h" 23 | 24 | #import 25 | 26 | #if TARGET_OS_IOS 27 | 28 | #import "AFHTTPSessionManager.h" 29 | #import "AFURLResponseSerialization.h" 30 | #import "AFURLRequestSerialization.h" 31 | 32 | @interface WKWebView (_AFNetworking) 33 | @property (readwrite, nonatomic, strong, setter = af_setURLSessionTask:) NSURLSessionDataTask *af_URLSessionTask; 34 | @end 35 | 36 | @implementation WKWebView (_AFNetworking) 37 | 38 | - (NSURLSessionDataTask *)af_URLSessionTask { 39 | return (NSURLSessionDataTask *)objc_getAssociatedObject(self, @selector(af_URLSessionTask)); 40 | } 41 | 42 | - (void)af_setURLSessionTask:(NSURLSessionDataTask *)af_URLSessionTask { 43 | objc_setAssociatedObject(self, @selector(af_URLSessionTask), af_URLSessionTask, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 44 | } 45 | 46 | @end 47 | 48 | #pragma mark - 49 | 50 | @implementation WKWebView (AFNetworking) 51 | 52 | - (AFHTTPSessionManager *)sessionManager { 53 | static AFHTTPSessionManager *_af_defaultHTTPSessionManager = nil; 54 | static dispatch_once_t onceToken; 55 | dispatch_once(&onceToken, ^{ 56 | _af_defaultHTTPSessionManager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; 57 | _af_defaultHTTPSessionManager.requestSerializer = [AFHTTPRequestSerializer serializer]; 58 | _af_defaultHTTPSessionManager.responseSerializer = [AFHTTPResponseSerializer serializer]; 59 | }); 60 | 61 | return objc_getAssociatedObject(self, @selector(sessionManager)) ?: _af_defaultHTTPSessionManager; 62 | } 63 | 64 | - (void)setSessionManager:(AFHTTPSessionManager *)sessionManager { 65 | objc_setAssociatedObject(self, @selector(sessionManager), sessionManager, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 66 | } 67 | 68 | - (AFHTTPResponseSerializer *)responseSerializer { 69 | static AFHTTPResponseSerializer *_af_defaultResponseSerializer = nil; 70 | static dispatch_once_t onceToken; 71 | dispatch_once(&onceToken, ^{ 72 | _af_defaultResponseSerializer = [AFHTTPResponseSerializer serializer]; 73 | }); 74 | 75 | return objc_getAssociatedObject(self, @selector(responseSerializer)) ?: _af_defaultResponseSerializer; 76 | } 77 | 78 | - (void)setResponseSerializer:(AFHTTPResponseSerializer *)responseSerializer { 79 | objc_setAssociatedObject(self, @selector(responseSerializer), responseSerializer, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 80 | } 81 | 82 | #pragma mark - 83 | 84 | - (void)loadRequest:(NSURLRequest *)request 85 | navigation:(WKNavigation * _Nonnull)navigation 86 | progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress 87 | success:(nullable NSString * (^)(NSHTTPURLResponse *response, NSString *HTML))success 88 | failure:(nullable void (^)(NSError *error))failure { 89 | [self loadRequest:request navigation:navigation MIMEType:nil textEncodingName:nil progress:progress success:^NSData * _Nonnull(NSHTTPURLResponse * _Nonnull response, NSData * _Nonnull data) { 90 | NSStringEncoding stringEncoding = NSUTF8StringEncoding; 91 | if (response.textEncodingName) { 92 | CFStringEncoding encoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)response.textEncodingName); 93 | if (encoding != kCFStringEncodingInvalidId) { 94 | stringEncoding = CFStringConvertEncodingToNSStringEncoding(encoding); 95 | } 96 | } 97 | 98 | NSString *string = [[NSString alloc] initWithData:data encoding:stringEncoding]; 99 | if (success) { 100 | string = success(response, string); 101 | } 102 | 103 | return [string dataUsingEncoding:stringEncoding]; 104 | } failure:failure]; 105 | } 106 | 107 | - (void)loadRequest:(NSURLRequest *)request 108 | navigation:(WKNavigation * _Nonnull)navigation 109 | MIMEType:(nullable NSString *)MIMEType 110 | textEncodingName:(nullable NSString *)textEncodingName 111 | progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress 112 | success:(nullable NSData * (^)(NSHTTPURLResponse *response, NSData *data))success 113 | failure:(nullable void (^)(NSError *error))failure { 114 | NSParameterAssert(request); 115 | 116 | if (self.af_URLSessionTask.state == NSURLSessionTaskStateRunning || self.af_URLSessionTask.state == NSURLSessionTaskStateSuspended) { 117 | [self.af_URLSessionTask cancel]; 118 | } 119 | self.af_URLSessionTask = nil; 120 | 121 | __weak __typeof(self)weakSelf = self; 122 | __block NSURLSessionDataTask *dataTask; 123 | __strong __typeof(weakSelf) strongSelf = weakSelf; 124 | __strong __typeof(weakSelf.navigationDelegate) strongSelfDelegate = strongSelf.navigationDelegate; 125 | dataTask = [self.sessionManager dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { 126 | if (error) { 127 | if (failure) { 128 | failure(error); 129 | } 130 | } else { 131 | if (success) { 132 | success((NSHTTPURLResponse *)response, responseObject); 133 | } 134 | [strongSelf loadData:responseObject MIMEType:MIMEType characterEncodingName:textEncodingName baseURL:[dataTask.currentRequest URL]]; 135 | 136 | if ([strongSelfDelegate respondsToSelector:@selector(webView:didFinishNavigation:)]) { 137 | [strongSelfDelegate webView:strongSelf didFinishNavigation:navigation]; 138 | } 139 | } 140 | }]; 141 | self.af_URLSessionTask = dataTask; 142 | if (progress != nil) { 143 | *progress = [self.sessionManager downloadProgressForTask:dataTask]; 144 | } 145 | [self.af_URLSessionTask resume]; 146 | 147 | if ([strongSelfDelegate respondsToSelector:@selector(webView:didStartProvisionalNavigation:)]) { 148 | [strongSelfDelegate webView:self didStartProvisionalNavigation:navigation]; 149 | } 150 | } 151 | 152 | @end 153 | 154 | #endif 155 | --------------------------------------------------------------------------------