├── .gitignore
├── JXPageListView.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ └── contents.xcworkspacedata
└── xcuserdata
│ └── jiaxin.xcuserdatad
│ └── xcschemes
│ └── xcschememanagement.plist
├── JXPageListView
├── AppDelegate.h
├── AppDelegate.m
├── Assets.xcassets
│ ├── AppIcon.appiconset
│ │ └── Contents.json
│ └── Contents.json
├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
├── Example
│ ├── MJRefresh
│ │ ├── Base
│ │ │ ├── MJRefreshAutoFooter.h
│ │ │ ├── MJRefreshAutoFooter.m
│ │ │ ├── MJRefreshBackFooter.h
│ │ │ ├── MJRefreshBackFooter.m
│ │ │ ├── MJRefreshComponent.h
│ │ │ ├── MJRefreshComponent.m
│ │ │ ├── MJRefreshFooter.h
│ │ │ ├── MJRefreshFooter.m
│ │ │ ├── MJRefreshHeader.h
│ │ │ └── MJRefreshHeader.m
│ │ ├── Custom
│ │ │ ├── Footer
│ │ │ │ ├── Auto
│ │ │ │ │ ├── MJRefreshAutoGifFooter.h
│ │ │ │ │ ├── MJRefreshAutoGifFooter.m
│ │ │ │ │ ├── MJRefreshAutoNormalFooter.h
│ │ │ │ │ ├── MJRefreshAutoNormalFooter.m
│ │ │ │ │ ├── MJRefreshAutoStateFooter.h
│ │ │ │ │ └── MJRefreshAutoStateFooter.m
│ │ │ │ └── Back
│ │ │ │ │ ├── MJRefreshBackGifFooter.h
│ │ │ │ │ ├── MJRefreshBackGifFooter.m
│ │ │ │ │ ├── MJRefreshBackNormalFooter.h
│ │ │ │ │ ├── MJRefreshBackNormalFooter.m
│ │ │ │ │ ├── MJRefreshBackStateFooter.h
│ │ │ │ │ └── MJRefreshBackStateFooter.m
│ │ │ └── Header
│ │ │ │ ├── MJRefreshGifHeader.h
│ │ │ │ ├── MJRefreshGifHeader.m
│ │ │ │ ├── MJRefreshNormalHeader.h
│ │ │ │ ├── MJRefreshNormalHeader.m
│ │ │ │ ├── MJRefreshStateHeader.h
│ │ │ │ └── MJRefreshStateHeader.m
│ │ ├── MJRefresh.bundle
│ │ │ ├── arrow@2x.png
│ │ │ ├── en.lproj
│ │ │ │ └── Localizable.strings
│ │ │ ├── zh-Hans.lproj
│ │ │ │ └── Localizable.strings
│ │ │ └── zh-Hant.lproj
│ │ │ │ └── Localizable.strings
│ │ ├── MJRefresh.h
│ │ ├── MJRefreshConst.h
│ │ ├── MJRefreshConst.m
│ │ ├── NSBundle+MJRefresh.h
│ │ ├── NSBundle+MJRefresh.m
│ │ ├── UIScrollView+MJExtension.h
│ │ ├── UIScrollView+MJExtension.m
│ │ ├── UIScrollView+MJRefresh.h
│ │ ├── UIScrollView+MJRefresh.m
│ │ ├── UIView+MJExtension.h
│ │ └── UIView+MJExtension.m
│ ├── NormalHotListView.h
│ ├── NormalHotListView.m
│ ├── NormalRecommendListView.h
│ ├── NormalRecommendListView.m
│ ├── NormalViewController.h
│ ├── NormalViewController.m
│ ├── PageViewController.h
│ ├── PageViewController.m
│ ├── TestListBaseView.h
│ ├── TestListBaseView.m
│ ├── TestTableView.h
│ ├── TestTableView.m
│ ├── UIWindow+JXSafeArea.h
│ └── UIWindow+JXSafeArea.m
├── Gif
│ ├── headerLoading.gif
│ ├── hudLoading.gif
│ ├── listScrollStateNoSave.gif
│ ├── listScrollStateSave.gif
│ └── scrollInteraction.gif
├── HUD
│ ├── MBProgressHUD.h
│ └── MBProgressHUD.m
├── Info.plist
├── JXCategoryView
│ ├── Base
│ │ ├── JXCategoryBaseCell.h
│ │ ├── JXCategoryBaseCell.m
│ │ ├── JXCategoryBaseCellModel.h
│ │ ├── JXCategoryBaseCellModel.m
│ │ ├── JXCategoryBaseView.h
│ │ └── JXCategoryBaseView.m
│ ├── Common
│ │ ├── JXCategoryCollectionView.h
│ │ ├── JXCategoryCollectionView.m
│ │ ├── JXCategoryFactory.h
│ │ ├── JXCategoryFactory.m
│ │ ├── JXCategoryIndicatorProtocol.h
│ │ ├── JXCategoryListVCContainerView.h
│ │ ├── JXCategoryListVCContainerView.m
│ │ ├── JXCategoryViewDefines.h
│ │ ├── UIColor+JXAdd.h
│ │ └── UIColor+JXAdd.m
│ ├── Dot
│ │ ├── JXCategoryDotCell.h
│ │ ├── JXCategoryDotCell.m
│ │ ├── JXCategoryDotCellModel.h
│ │ ├── JXCategoryDotCellModel.m
│ │ ├── JXCategoryDotView.h
│ │ └── JXCategoryDotView.m
│ ├── Image
│ │ ├── JXCategoryImageCell.h
│ │ ├── JXCategoryImageCell.m
│ │ ├── JXCategoryImageCellModel.h
│ │ ├── JXCategoryImageCellModel.m
│ │ ├── JXCategoryImageView.h
│ │ └── JXCategoryImageView.m
│ ├── Indicator
│ │ ├── IndicatorViews
│ │ │ ├── JXCategoryIndicatorBackgroundView.h
│ │ │ ├── JXCategoryIndicatorBackgroundView.m
│ │ │ ├── JXCategoryIndicatorBallView.h
│ │ │ ├── JXCategoryIndicatorBallView.m
│ │ │ ├── JXCategoryIndicatorComponentView.h
│ │ │ ├── JXCategoryIndicatorComponentView.m
│ │ │ ├── JXCategoryIndicatorImageView.h
│ │ │ ├── JXCategoryIndicatorImageView.m
│ │ │ ├── JXCategoryIndicatorLineView.h
│ │ │ ├── JXCategoryIndicatorLineView.m
│ │ │ ├── JXCategoryIndicatorTriangleView.h
│ │ │ └── JXCategoryIndicatorTriangleView.m
│ │ ├── JXCategoryIndicatorCell.h
│ │ ├── JXCategoryIndicatorCell.m
│ │ ├── JXCategoryIndicatorCellModel.h
│ │ ├── JXCategoryIndicatorCellModel.m
│ │ ├── JXCategoryIndicatorView.h
│ │ └── JXCategoryIndicatorView.m
│ ├── JXCategoryView.h
│ ├── Number
│ │ ├── JXCategoryNumberCell.h
│ │ ├── JXCategoryNumberCell.m
│ │ ├── JXCategoryNumberCellModel.h
│ │ ├── JXCategoryNumberCellModel.m
│ │ ├── JXCategoryNumberView.h
│ │ └── JXCategoryNumberView.m
│ ├── Title
│ │ ├── JXCategoryTitleCell.h
│ │ ├── JXCategoryTitleCell.m
│ │ ├── JXCategoryTitleCellModel.h
│ │ ├── JXCategoryTitleCellModel.m
│ │ ├── JXCategoryTitleView.h
│ │ └── JXCategoryTitleView.m
│ └── TitleImage
│ │ ├── JXCategoryTitleImageCell.h
│ │ ├── JXCategoryTitleImageCell.m
│ │ ├── JXCategoryTitleImageCellModel.h
│ │ ├── JXCategoryTitleImageCellModel.m
│ │ ├── JXCategoryTitleImageView.h
│ │ └── JXCategoryTitleImageView.m
├── PageListView
│ ├── JXPageListContainerView.h
│ ├── JXPageListContainerView.m
│ ├── JXPageListMainTableView.h
│ ├── JXPageListMainTableView.m
│ ├── JXPageListView.h
│ └── JXPageListView.m
├── ViewController.h
├── ViewController.m
└── main.m
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4 |
5 | ## Build generated
6 | build/
7 | DerivedData/
8 |
9 | ## Various settings
10 | *.pbxuser
11 | !default.pbxuser
12 | *.mode1v3
13 | !default.mode1v3
14 | *.mode2v3
15 | !default.mode2v3
16 | *.perspectivev3
17 | !default.perspectivev3
18 | xcuserdata/
19 |
20 | ## Other
21 | *.moved-aside
22 | *.xccheckout
23 | *.xcscmblueprint
24 |
25 | ## Obj-C/Swift specific
26 | *.hmap
27 | *.ipa
28 | *.dSYM.zip
29 | *.dSYM
30 |
31 | # CocoaPods
32 | #
33 | # We recommend against adding the Pods directory to your .gitignore. However
34 | # you should judge for yourself, the pros and cons are mentioned at:
35 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
36 | #
37 | # Pods/
38 |
39 | # Carthage
40 | #
41 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
42 | # Carthage/Checkouts
43 |
44 | Carthage/Build
45 |
46 | # fastlane
47 | #
48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
49 | # screenshots whenever they are needed.
50 | # For more information about the recommended setup visit:
51 | # https://docs.fastlane.tools/best-practices/source-control/#source-control
52 |
53 | fastlane/report.xml
54 | fastlane/Preview.html
55 | fastlane/screenshots/**/*.png
56 | fastlane/test_output
57 |
58 | # Code Injection
59 | #
60 | # After new code Injection tools there's a generated folder /iOSInjectionProject
61 | # https://github.com/johnno1962/injectionforxcode
62 |
63 | iOSInjectionProject/
64 |
--------------------------------------------------------------------------------
/JXPageListView.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/JXPageListView.xcodeproj/xcuserdata/jiaxin.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | JXPageListView.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 | JXPageListView.xcscheme_^#shared#^_
13 |
14 | orderHint
15 | 0
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/JXPageListView/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/14.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/JXPageListView/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/14.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 |
24 | - (void)applicationWillResignActive:(UIApplication *)application {
25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
27 | }
28 |
29 |
30 | - (void)applicationDidEnterBackground:(UIApplication *)application {
31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
33 | }
34 |
35 |
36 | - (void)applicationWillEnterForeground:(UIApplication *)application {
37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
38 | }
39 |
40 |
41 | - (void)applicationDidBecomeActive:(UIApplication *)application {
42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
43 | }
44 |
45 |
46 | - (void)applicationWillTerminate:(UIApplication *)application {
47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
48 | }
49 |
50 |
51 | @end
52 |
--------------------------------------------------------------------------------
/JXPageListView/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 | }
--------------------------------------------------------------------------------
/JXPageListView/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/JXPageListView/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Base/MJRefreshAutoFooter.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshAutoFooter.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshFooter.h"
10 |
11 | @interface MJRefreshAutoFooter : MJRefreshFooter
12 | /** 是否自动刷新(默认为YES) */
13 | @property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh;
14 |
15 | /** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */
16 | @property (assign, nonatomic) CGFloat appearencePercentTriggerAutoRefresh MJRefreshDeprecated("请使用triggerAutomaticallyRefreshPercent属性");
17 |
18 | /** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */
19 | @property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent;
20 |
21 | /** 是否每一次拖拽只发一次请求 */
22 | @property (assign, nonatomic, getter=isOnlyRefreshPerDrag) BOOL onlyRefreshPerDrag;
23 | @end
24 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Base/MJRefreshAutoFooter.m:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshAutoFooter.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshAutoFooter.h"
10 |
11 | @interface MJRefreshAutoFooter()
12 | /** 一个新的拖拽 */
13 | @property (assign, nonatomic, getter=isOneNewPan) BOOL oneNewPan;
14 | @end
15 |
16 | @implementation MJRefreshAutoFooter
17 |
18 | #pragma mark - 初始化
19 | - (void)willMoveToSuperview:(UIView *)newSuperview
20 | {
21 | [super willMoveToSuperview:newSuperview];
22 |
23 | if (newSuperview) { // 新的父控件
24 | if (self.hidden == NO) {
25 | self.scrollView.mj_insetB += self.mj_h;
26 | }
27 |
28 | // 设置位置
29 | self.mj_y = _scrollView.mj_contentH;
30 | } else { // 被移除了
31 | if (self.hidden == NO) {
32 | self.scrollView.mj_insetB -= self.mj_h;
33 | }
34 | }
35 | }
36 |
37 | #pragma mark - 过期方法
38 | - (void)setAppearencePercentTriggerAutoRefresh:(CGFloat)appearencePercentTriggerAutoRefresh
39 | {
40 | self.triggerAutomaticallyRefreshPercent = appearencePercentTriggerAutoRefresh;
41 | }
42 |
43 | - (CGFloat)appearencePercentTriggerAutoRefresh
44 | {
45 | return self.triggerAutomaticallyRefreshPercent;
46 | }
47 |
48 | #pragma mark - 实现父类的方法
49 | - (void)prepare
50 | {
51 | [super prepare];
52 |
53 | // 默认底部控件100%出现时才会自动刷新
54 | self.triggerAutomaticallyRefreshPercent = 1.0;
55 |
56 | // 设置为默认状态
57 | self.automaticallyRefresh = YES;
58 |
59 | // 默认是当offset达到条件就发送请求(可连续)
60 | self.onlyRefreshPerDrag = NO;
61 | }
62 |
63 | - (void)scrollViewContentSizeDidChange:(NSDictionary *)change
64 | {
65 | [super scrollViewContentSizeDidChange:change];
66 |
67 | // 设置位置
68 | self.mj_y = self.scrollView.mj_contentH;
69 | }
70 |
71 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
72 | {
73 | [super scrollViewContentOffsetDidChange:change];
74 |
75 | if (self.state != MJRefreshStateIdle || !self.automaticallyRefresh || self.mj_y == 0) return;
76 |
77 | if (_scrollView.mj_insetT + _scrollView.mj_contentH > _scrollView.mj_h) { // 内容超过一个屏幕
78 | // 这里的_scrollView.mj_contentH替换掉self.mj_y更为合理
79 | if (_scrollView.mj_offsetY >= _scrollView.mj_contentH - _scrollView.mj_h + self.mj_h * self.triggerAutomaticallyRefreshPercent + _scrollView.mj_insetB - self.mj_h) {
80 | // 防止手松开时连续调用
81 | CGPoint old = [change[@"old"] CGPointValue];
82 | CGPoint new = [change[@"new"] CGPointValue];
83 | if (new.y <= old.y) return;
84 |
85 | // 当底部刷新控件完全出现时,才刷新
86 | [self beginRefreshing];
87 | }
88 | }
89 | }
90 |
91 | - (void)scrollViewPanStateDidChange:(NSDictionary *)change
92 | {
93 | [super scrollViewPanStateDidChange:change];
94 |
95 | if (self.state != MJRefreshStateIdle) return;
96 |
97 | UIGestureRecognizerState panState = _scrollView.panGestureRecognizer.state;
98 | if (panState == UIGestureRecognizerStateEnded) {// 手松开
99 | if (_scrollView.mj_insetT + _scrollView.mj_contentH <= _scrollView.mj_h) { // 不够一个屏幕
100 | if (_scrollView.mj_offsetY >= - _scrollView.mj_insetT) { // 向上拽
101 | [self beginRefreshing];
102 | }
103 | } else { // 超出一个屏幕
104 | if (_scrollView.mj_offsetY >= _scrollView.mj_contentH + _scrollView.mj_insetB - _scrollView.mj_h) {
105 | [self beginRefreshing];
106 | }
107 | }
108 | } else if (panState == UIGestureRecognizerStateBegan) {
109 | self.oneNewPan = YES;
110 | }
111 | }
112 |
113 | - (void)beginRefreshing
114 | {
115 | if (!self.isOneNewPan && self.isOnlyRefreshPerDrag) return;
116 |
117 | [super beginRefreshing];
118 |
119 | self.oneNewPan = NO;
120 | }
121 |
122 | - (void)setState:(MJRefreshState)state
123 | {
124 | MJRefreshCheckState
125 |
126 | if (state == MJRefreshStateRefreshing) {
127 | [self executeRefreshingCallback];
128 | } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) {
129 | if (MJRefreshStateRefreshing == oldState) {
130 | if (self.endRefreshingCompletionBlock) {
131 | self.endRefreshingCompletionBlock();
132 | }
133 | }
134 | }
135 | }
136 |
137 | - (void)setHidden:(BOOL)hidden
138 | {
139 | BOOL lastHidden = self.isHidden;
140 |
141 | [super setHidden:hidden];
142 |
143 | if (!lastHidden && hidden) {
144 | self.state = MJRefreshStateIdle;
145 |
146 | self.scrollView.mj_insetB -= self.mj_h;
147 | } else if (lastHidden && !hidden) {
148 | self.scrollView.mj_insetB += self.mj_h;
149 |
150 | // 设置位置
151 | self.mj_y = _scrollView.mj_contentH;
152 | }
153 | }
154 | @end
155 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Base/MJRefreshBackFooter.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshBackFooter.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshFooter.h"
10 |
11 | @interface MJRefreshBackFooter : MJRefreshFooter
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Base/MJRefreshBackFooter.m:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshBackFooter.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshBackFooter.h"
10 |
11 | @interface MJRefreshBackFooter()
12 | @property (assign, nonatomic) NSInteger lastRefreshCount;
13 | @property (assign, nonatomic) CGFloat lastBottomDelta;
14 | @end
15 |
16 | @implementation MJRefreshBackFooter
17 |
18 | #pragma mark - 初始化
19 | - (void)willMoveToSuperview:(UIView *)newSuperview
20 | {
21 | [super willMoveToSuperview:newSuperview];
22 |
23 | [self scrollViewContentSizeDidChange:nil];
24 | }
25 |
26 | #pragma mark - 实现父类的方法
27 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
28 | {
29 | [super scrollViewContentOffsetDidChange:change];
30 |
31 | // 如果正在刷新,直接返回
32 | if (self.state == MJRefreshStateRefreshing) return;
33 |
34 | _scrollViewOriginalInset = self.scrollView.mj_inset;
35 |
36 | // 当前的contentOffset
37 | CGFloat currentOffsetY = self.scrollView.mj_offsetY;
38 | // 尾部控件刚好出现的offsetY
39 | CGFloat happenOffsetY = [self happenOffsetY];
40 | // 如果是向下滚动到看不见尾部控件,直接返回
41 | if (currentOffsetY <= happenOffsetY) return;
42 |
43 | CGFloat pullingPercent = (currentOffsetY - happenOffsetY) / self.mj_h;
44 |
45 | // 如果已全部加载,仅设置pullingPercent,然后返回
46 | if (self.state == MJRefreshStateNoMoreData) {
47 | self.pullingPercent = pullingPercent;
48 | return;
49 | }
50 |
51 | if (self.scrollView.isDragging) {
52 | self.pullingPercent = pullingPercent;
53 | // 普通 和 即将刷新 的临界点
54 | CGFloat normal2pullingOffsetY = happenOffsetY + self.mj_h;
55 |
56 | if (self.state == MJRefreshStateIdle && currentOffsetY > normal2pullingOffsetY) {
57 | // 转为即将刷新状态
58 | self.state = MJRefreshStatePulling;
59 | } else if (self.state == MJRefreshStatePulling && currentOffsetY <= normal2pullingOffsetY) {
60 | // 转为普通状态
61 | self.state = MJRefreshStateIdle;
62 | }
63 | } else if (self.state == MJRefreshStatePulling) {// 即将刷新 && 手松开
64 | // 开始刷新
65 | [self beginRefreshing];
66 | } else if (pullingPercent < 1) {
67 | self.pullingPercent = pullingPercent;
68 | }
69 | }
70 |
71 | - (void)scrollViewContentSizeDidChange:(NSDictionary *)change
72 | {
73 | [super scrollViewContentSizeDidChange:change];
74 |
75 | // 内容的高度
76 | CGFloat contentHeight = self.scrollView.mj_contentH + self.ignoredScrollViewContentInsetBottom;
77 | // 表格的高度
78 | CGFloat scrollHeight = self.scrollView.mj_h - self.scrollViewOriginalInset.top - self.scrollViewOriginalInset.bottom + self.ignoredScrollViewContentInsetBottom;
79 | // 设置位置和尺寸
80 | self.mj_y = MAX(contentHeight, scrollHeight);
81 | }
82 |
83 | - (void)setState:(MJRefreshState)state
84 | {
85 | MJRefreshCheckState
86 |
87 | // 根据状态来设置属性
88 | if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) {
89 | // 刷新完毕
90 | if (MJRefreshStateRefreshing == oldState) {
91 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{
92 | self.scrollView.mj_insetB -= self.lastBottomDelta;
93 |
94 | // 自动调整透明度
95 | if (self.isAutomaticallyChangeAlpha) self.alpha = 0.0;
96 | } completion:^(BOOL finished) {
97 | self.pullingPercent = 0.0;
98 |
99 | if (self.endRefreshingCompletionBlock) {
100 | self.endRefreshingCompletionBlock();
101 | }
102 | }];
103 | }
104 |
105 | CGFloat deltaH = [self heightForContentBreakView];
106 | // 刚刷新完毕
107 | if (MJRefreshStateRefreshing == oldState && deltaH > 0 && self.scrollView.mj_totalDataCount != self.lastRefreshCount) {
108 | self.scrollView.mj_offsetY = self.scrollView.mj_offsetY;
109 | }
110 | } else if (state == MJRefreshStateRefreshing) {
111 | // 记录刷新前的数量
112 | self.lastRefreshCount = self.scrollView.mj_totalDataCount;
113 |
114 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{
115 | CGFloat bottom = self.mj_h + self.scrollViewOriginalInset.bottom;
116 | CGFloat deltaH = [self heightForContentBreakView];
117 | if (deltaH < 0) { // 如果内容高度小于view的高度
118 | bottom -= deltaH;
119 | }
120 | self.lastBottomDelta = bottom - self.scrollView.mj_insetB;
121 | self.scrollView.mj_insetB = bottom;
122 | self.scrollView.mj_offsetY = [self happenOffsetY] + self.mj_h;
123 | } completion:^(BOOL finished) {
124 | [self executeRefreshingCallback];
125 | }];
126 | }
127 | }
128 | #pragma mark - 私有方法
129 | #pragma mark 获得scrollView的内容 超出 view 的高度
130 | - (CGFloat)heightForContentBreakView
131 | {
132 | CGFloat h = self.scrollView.frame.size.height - self.scrollViewOriginalInset.bottom - self.scrollViewOriginalInset.top;
133 | return self.scrollView.contentSize.height - h;
134 | }
135 |
136 | #pragma mark 刚好看到上拉刷新控件时的contentOffset.y
137 | - (CGFloat)happenOffsetY
138 | {
139 | CGFloat deltaH = [self heightForContentBreakView];
140 | if (deltaH > 0) {
141 | return deltaH - self.scrollViewOriginalInset.top;
142 | } else {
143 | return - self.scrollViewOriginalInset.top;
144 | }
145 | }
146 | @end
147 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Base/MJRefreshComponent.h:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | // MJRefreshComponent.h
4 | // MJRefreshExample
5 | //
6 | // Created by MJ Lee on 15/3/4.
7 | // Copyright (c) 2015年 小码哥. All rights reserved.
8 | // 刷新控件的基类
9 |
10 | #import
11 | #import "MJRefreshConst.h"
12 | #import "UIView+MJExtension.h"
13 | #import "UIScrollView+MJExtension.h"
14 | #import "UIScrollView+MJRefresh.h"
15 | #import "NSBundle+MJRefresh.h"
16 |
17 | /** 刷新控件的状态 */
18 | typedef NS_ENUM(NSInteger, MJRefreshState) {
19 | /** 普通闲置状态 */
20 | MJRefreshStateIdle = 1,
21 | /** 松开就可以进行刷新的状态 */
22 | MJRefreshStatePulling,
23 | /** 正在刷新中的状态 */
24 | MJRefreshStateRefreshing,
25 | /** 即将刷新的状态 */
26 | MJRefreshStateWillRefresh,
27 | /** 所有数据加载完毕,没有更多的数据了 */
28 | MJRefreshStateNoMoreData
29 | };
30 |
31 | /** 进入刷新状态的回调 */
32 | typedef void (^MJRefreshComponentRefreshingBlock)(void);
33 | /** 开始刷新后的回调(进入刷新状态后的回调) */
34 | typedef void (^MJRefreshComponentbeginRefreshingCompletionBlock)(void);
35 | /** 结束刷新后的回调 */
36 | typedef void (^MJRefreshComponentEndRefreshingCompletionBlock)(void);
37 |
38 | /** 刷新控件的基类 */
39 | @interface MJRefreshComponent : UIView
40 | {
41 | /** 记录scrollView刚开始的inset */
42 | UIEdgeInsets _scrollViewOriginalInset;
43 | /** 父控件 */
44 | __weak UIScrollView *_scrollView;
45 | }
46 | #pragma mark - 刷新回调
47 | /** 正在刷新的回调 */
48 | @property (copy, nonatomic) MJRefreshComponentRefreshingBlock refreshingBlock;
49 | /** 设置回调对象和回调方法 */
50 | - (void)setRefreshingTarget:(id)target refreshingAction:(SEL)action;
51 |
52 | /** 回调对象 */
53 | @property (weak, nonatomic) id refreshingTarget;
54 | /** 回调方法 */
55 | @property (assign, nonatomic) SEL refreshingAction;
56 | /** 触发回调(交给子类去调用) */
57 | - (void)executeRefreshingCallback;
58 |
59 | #pragma mark - 刷新状态控制
60 | /** 进入刷新状态 */
61 | - (void)beginRefreshing;
62 | - (void)beginRefreshingWithCompletionBlock:(void (^)(void))completionBlock;
63 | /** 开始刷新后的回调(进入刷新状态后的回调) */
64 | @property (copy, nonatomic) MJRefreshComponentbeginRefreshingCompletionBlock beginRefreshingCompletionBlock;
65 | /** 结束刷新的回调 */
66 | @property (copy, nonatomic) MJRefreshComponentEndRefreshingCompletionBlock endRefreshingCompletionBlock;
67 | /** 结束刷新状态 */
68 | - (void)endRefreshing;
69 | - (void)endRefreshingWithCompletionBlock:(void (^)(void))completionBlock;
70 | /** 是否正在刷新 */
71 | @property (assign, nonatomic, readonly, getter=isRefreshing) BOOL refreshing;
72 | //- (BOOL)isRefreshing;
73 | /** 刷新状态 一般交给子类内部实现 */
74 | @property (assign, nonatomic) MJRefreshState state;
75 |
76 | #pragma mark - 交给子类去访问
77 | /** 记录scrollView刚开始的inset */
78 | @property (assign, nonatomic, readonly) UIEdgeInsets scrollViewOriginalInset;
79 | /** 父控件 */
80 | @property (weak, nonatomic, readonly) UIScrollView *scrollView;
81 |
82 | #pragma mark - 交给子类们去实现
83 | /** 初始化 */
84 | - (void)prepare NS_REQUIRES_SUPER;
85 | /** 摆放子控件frame */
86 | - (void)placeSubviews NS_REQUIRES_SUPER;
87 | /** 当scrollView的contentOffset发生改变的时候调用 */
88 | - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change NS_REQUIRES_SUPER;
89 | /** 当scrollView的contentSize发生改变的时候调用 */
90 | - (void)scrollViewContentSizeDidChange:(NSDictionary *)change NS_REQUIRES_SUPER;
91 | /** 当scrollView的拖拽状态发生改变的时候调用 */
92 | - (void)scrollViewPanStateDidChange:(NSDictionary *)change NS_REQUIRES_SUPER;
93 |
94 |
95 | #pragma mark - 其他
96 | /** 拉拽的百分比(交给子类重写) */
97 | @property (assign, nonatomic) CGFloat pullingPercent;
98 | /** 根据拖拽比例自动切换透明度 */
99 | @property (assign, nonatomic, getter=isAutoChangeAlpha) BOOL autoChangeAlpha MJRefreshDeprecated("请使用automaticallyChangeAlpha属性");
100 | /** 根据拖拽比例自动切换透明度 */
101 | @property (assign, nonatomic, getter=isAutomaticallyChangeAlpha) BOOL automaticallyChangeAlpha;
102 | @end
103 |
104 | @interface UILabel(MJRefresh)
105 | + (instancetype)mj_label;
106 | - (CGFloat)mj_textWith;
107 | @end
108 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Base/MJRefreshFooter.h:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | // MJRefreshFooter.h
4 | // MJRefreshExample
5 | //
6 | // Created by MJ Lee on 15/3/5.
7 | // Copyright (c) 2015年 小码哥. All rights reserved.
8 | // 上拉刷新控件
9 |
10 | #import "MJRefreshComponent.h"
11 |
12 | @interface MJRefreshFooter : MJRefreshComponent
13 | /** 创建footer */
14 | + (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
15 | /** 创建footer */
16 | + (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
17 |
18 | /** 提示没有更多的数据 */
19 | - (void)endRefreshingWithNoMoreData;
20 | - (void)noticeNoMoreData MJRefreshDeprecated("使用endRefreshingWithNoMoreData");
21 |
22 | /** 重置没有更多的数据(消除没有更多数据的状态) */
23 | - (void)resetNoMoreData;
24 |
25 | /** 忽略多少scrollView的contentInset的bottom */
26 | @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetBottom;
27 |
28 | /** 自动根据有无数据来显示和隐藏(有数据就显示,没有数据隐藏。默认是NO) */
29 | @property (assign, nonatomic, getter=isAutomaticallyHidden) BOOL automaticallyHidden MJRefreshDeprecated("不建议使用此属性,开发者请自行控制footer的显示和隐藏。基于安全考虑,在未来的某些版本此属性可能作废");
30 | @end
31 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Base/MJRefreshFooter.m:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | // MJRefreshFooter.m
4 | // MJRefreshExample
5 | //
6 | // Created by MJ Lee on 15/3/5.
7 | // Copyright (c) 2015年 小码哥. All rights reserved.
8 | //
9 |
10 | #import "MJRefreshFooter.h"
11 | #include "UIScrollView+MJRefresh.h"
12 |
13 | @interface MJRefreshFooter()
14 |
15 | @end
16 |
17 | @implementation MJRefreshFooter
18 | #pragma mark - 构造方法
19 | + (instancetype)footerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock
20 | {
21 | MJRefreshFooter *cmp = [[self alloc] init];
22 | cmp.refreshingBlock = refreshingBlock;
23 | return cmp;
24 | }
25 | + (instancetype)footerWithRefreshingTarget:(id)target refreshingAction:(SEL)action
26 | {
27 | MJRefreshFooter *cmp = [[self alloc] init];
28 | [cmp setRefreshingTarget:target refreshingAction:action];
29 | return cmp;
30 | }
31 |
32 | #pragma mark - 重写父类的方法
33 | - (void)prepare
34 | {
35 | [super prepare];
36 |
37 | // 设置自己的高度
38 | self.mj_h = MJRefreshFooterHeight;
39 |
40 | // 默认不会自动隐藏
41 | // self.automaticallyHidden = NO;
42 | }
43 |
44 | - (void)willMoveToSuperview:(UIView *)newSuperview
45 | {
46 | [super willMoveToSuperview:newSuperview];
47 |
48 | if (newSuperview) {
49 | // 监听scrollView数据的变化
50 | if ([self.scrollView isKindOfClass:[UITableView class]] || [self.scrollView isKindOfClass:[UICollectionView class]]) {
51 | [self.scrollView setMj_reloadDataBlock:^(NSInteger totalDataCount) {
52 | // if (self.isAutomaticallyHidden) {
53 | // self.hidden = (totalDataCount == 0);
54 | // }
55 | }];
56 | }
57 | }
58 | }
59 |
60 | #pragma mark - 公共方法
61 | - (void)endRefreshingWithNoMoreData
62 | {
63 | MJRefreshDispatchAsyncOnMainQueue(self.state = MJRefreshStateNoMoreData;)
64 | }
65 |
66 | - (void)noticeNoMoreData
67 | {
68 | [self endRefreshingWithNoMoreData];
69 | }
70 |
71 | - (void)resetNoMoreData
72 | {
73 | MJRefreshDispatchAsyncOnMainQueue(self.state = MJRefreshStateIdle;)
74 | }
75 |
76 | - (void)setAutomaticallyHidden:(BOOL)automaticallyHidden
77 | {
78 | _automaticallyHidden = automaticallyHidden;
79 | }
80 | @end
81 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Base/MJRefreshHeader.h:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | // MJRefreshHeader.h
4 | // MJRefreshExample
5 | //
6 | // Created by MJ Lee on 15/3/4.
7 | // Copyright (c) 2015年 小码哥. All rights reserved.
8 | // 下拉刷新控件:负责监控用户下拉的状态
9 |
10 | #import "MJRefreshComponent.h"
11 |
12 | @interface MJRefreshHeader : MJRefreshComponent
13 | /** 创建header */
14 | + (instancetype)headerWithRefreshingBlock:(MJRefreshComponentRefreshingBlock)refreshingBlock;
15 | /** 创建header */
16 | + (instancetype)headerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
17 |
18 | /** 这个key用来存储上一次下拉刷新成功的时间 */
19 | @property (copy, nonatomic) NSString *lastUpdatedTimeKey;
20 | /** 上一次下拉刷新成功的时间 */
21 | @property (strong, nonatomic, readonly) NSDate *lastUpdatedTime;
22 |
23 | /** 忽略多少scrollView的contentInset的top */
24 | @property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetTop;
25 | @end
26 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshAutoGifFooter.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshAutoStateFooter.h"
10 |
11 | @interface MJRefreshAutoGifFooter : MJRefreshAutoStateFooter
12 | @property (weak, nonatomic, readonly) UIImageView *gifView;
13 |
14 | /** 设置state状态下的动画图片images 动画持续时间duration*/
15 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state;
16 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state;
17 | @end
18 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Auto/MJRefreshAutoGifFooter.m:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshAutoGifFooter.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshAutoGifFooter.h"
10 |
11 | @interface MJRefreshAutoGifFooter()
12 | {
13 | __unsafe_unretained UIImageView *_gifView;
14 | }
15 | /** 所有状态对应的动画图片 */
16 | @property (strong, nonatomic) NSMutableDictionary *stateImages;
17 | /** 所有状态对应的动画时间 */
18 | @property (strong, nonatomic) NSMutableDictionary *stateDurations;
19 | @end
20 |
21 | @implementation MJRefreshAutoGifFooter
22 | #pragma mark - 懒加载
23 | - (UIImageView *)gifView
24 | {
25 | if (!_gifView) {
26 | UIImageView *gifView = [[UIImageView alloc] init];
27 | [self addSubview:_gifView = gifView];
28 | }
29 | return _gifView;
30 | }
31 |
32 | - (NSMutableDictionary *)stateImages
33 | {
34 | if (!_stateImages) {
35 | self.stateImages = [NSMutableDictionary dictionary];
36 | }
37 | return _stateImages;
38 | }
39 |
40 | - (NSMutableDictionary *)stateDurations
41 | {
42 | if (!_stateDurations) {
43 | self.stateDurations = [NSMutableDictionary dictionary];
44 | }
45 | return _stateDurations;
46 | }
47 |
48 | #pragma mark - 公共方法
49 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state
50 | {
51 | if (images == nil) return;
52 |
53 | self.stateImages[@(state)] = images;
54 | self.stateDurations[@(state)] = @(duration);
55 |
56 | /* 根据图片设置控件的高度 */
57 | UIImage *image = [images firstObject];
58 | if (image.size.height > self.mj_h) {
59 | self.mj_h = image.size.height;
60 | }
61 | }
62 |
63 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state
64 | {
65 | [self setImages:images duration:images.count * 0.1 forState:state];
66 | }
67 |
68 | #pragma mark - 实现父类的方法
69 | - (void)prepare
70 | {
71 | [super prepare];
72 |
73 | // 初始化间距
74 | self.labelLeftInset = 20;
75 | }
76 |
77 | - (void)placeSubviews
78 | {
79 | [super placeSubviews];
80 |
81 | if (self.gifView.constraints.count) return;
82 |
83 | self.gifView.frame = self.bounds;
84 | if (self.isRefreshingTitleHidden) {
85 | self.gifView.contentMode = UIViewContentModeCenter;
86 | } else {
87 | self.gifView.contentMode = UIViewContentModeRight;
88 | self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5;
89 | }
90 | }
91 |
92 | - (void)setState:(MJRefreshState)state
93 | {
94 | MJRefreshCheckState
95 |
96 | // 根据状态做事情
97 | if (state == MJRefreshStateRefreshing) {
98 | NSArray *images = self.stateImages[@(state)];
99 | if (images.count == 0) return;
100 | [self.gifView stopAnimating];
101 |
102 | self.gifView.hidden = NO;
103 | if (images.count == 1) { // 单张图片
104 | self.gifView.image = [images lastObject];
105 | } else { // 多张图片
106 | self.gifView.animationImages = images;
107 | self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue];
108 | [self.gifView startAnimating];
109 | }
110 | } else if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) {
111 | [self.gifView stopAnimating];
112 | self.gifView.hidden = YES;
113 | }
114 | }
115 | @end
116 |
117 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshAutoNormalFooter.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshAutoStateFooter.h"
10 |
11 | @interface MJRefreshAutoNormalFooter : MJRefreshAutoStateFooter
12 | /** 菊花的样式 */
13 | @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle;
14 | @end
15 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.m:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshAutoNormalFooter.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshAutoNormalFooter.h"
10 |
11 | @interface MJRefreshAutoNormalFooter()
12 | @property (weak, nonatomic) UIActivityIndicatorView *loadingView;
13 | @end
14 |
15 | @implementation MJRefreshAutoNormalFooter
16 | #pragma mark - 懒加载子控件
17 | - (UIActivityIndicatorView *)loadingView
18 | {
19 | if (!_loadingView) {
20 | UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle];
21 | loadingView.hidesWhenStopped = YES;
22 | [self addSubview:_loadingView = loadingView];
23 | }
24 | return _loadingView;
25 | }
26 |
27 | - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle
28 | {
29 | _activityIndicatorViewStyle = activityIndicatorViewStyle;
30 |
31 | self.loadingView = nil;
32 | [self setNeedsLayout];
33 | }
34 | #pragma mark - 重写父类的方法
35 | - (void)prepare
36 | {
37 | [super prepare];
38 |
39 | self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
40 | }
41 |
42 | - (void)placeSubviews
43 | {
44 | [super placeSubviews];
45 |
46 | if (self.loadingView.constraints.count) return;
47 |
48 | // 圈圈
49 | CGFloat loadingCenterX = self.mj_w * 0.5;
50 | if (!self.isRefreshingTitleHidden) {
51 | loadingCenterX -= self.stateLabel.mj_textWith * 0.5 + self.labelLeftInset;
52 | }
53 | CGFloat loadingCenterY = self.mj_h * 0.5;
54 | self.loadingView.center = CGPointMake(loadingCenterX, loadingCenterY);
55 | }
56 |
57 | - (void)setState:(MJRefreshState)state
58 | {
59 | MJRefreshCheckState
60 |
61 | // 根据状态做事情
62 | if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) {
63 | [self.loadingView stopAnimating];
64 | } else if (state == MJRefreshStateRefreshing) {
65 | [self.loadingView startAnimating];
66 | }
67 | }
68 |
69 | @end
70 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshAutoStateFooter.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/6/13.
6 | // Copyright © 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshAutoFooter.h"
10 |
11 | @interface MJRefreshAutoStateFooter : MJRefreshAutoFooter
12 | /** 文字距离圈圈、箭头的距离 */
13 | @property (assign, nonatomic) CGFloat labelLeftInset;
14 | /** 显示刷新状态的label */
15 | @property (weak, nonatomic, readonly) UILabel *stateLabel;
16 |
17 | /** 设置state状态下的文字 */
18 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state;
19 |
20 | /** 隐藏刷新状态的文字 */
21 | @property (assign, nonatomic, getter=isRefreshingTitleHidden) BOOL refreshingTitleHidden;
22 | @end
23 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshAutoStateFooter.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/6/13.
6 | // Copyright © 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshAutoStateFooter.h"
10 |
11 | @interface MJRefreshAutoStateFooter()
12 | {
13 | /** 显示刷新状态的label */
14 | __unsafe_unretained UILabel *_stateLabel;
15 | }
16 | /** 所有状态对应的文字 */
17 | @property (strong, nonatomic) NSMutableDictionary *stateTitles;
18 | @end
19 |
20 | @implementation MJRefreshAutoStateFooter
21 | #pragma mark - 懒加载
22 | - (NSMutableDictionary *)stateTitles
23 | {
24 | if (!_stateTitles) {
25 | self.stateTitles = [NSMutableDictionary dictionary];
26 | }
27 | return _stateTitles;
28 | }
29 |
30 | - (UILabel *)stateLabel
31 | {
32 | if (!_stateLabel) {
33 | [self addSubview:_stateLabel = [UILabel mj_label]];
34 | }
35 | return _stateLabel;
36 | }
37 |
38 | #pragma mark - 公共方法
39 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state
40 | {
41 | if (title == nil) return;
42 | self.stateTitles[@(state)] = title;
43 | self.stateLabel.text = self.stateTitles[@(self.state)];
44 | }
45 |
46 | #pragma mark - 私有方法
47 | - (void)stateLabelClick
48 | {
49 | if (self.state == MJRefreshStateIdle) {
50 | [self beginRefreshing];
51 | }
52 | }
53 |
54 | #pragma mark - 重写父类的方法
55 | - (void)prepare
56 | {
57 | [super prepare];
58 |
59 | // 初始化间距
60 | self.labelLeftInset = MJRefreshLabelLeftInset;
61 |
62 | // 初始化文字
63 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterIdleText] forState:MJRefreshStateIdle];
64 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterRefreshingText] forState:MJRefreshStateRefreshing];
65 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshAutoFooterNoMoreDataText] forState:MJRefreshStateNoMoreData];
66 |
67 | // 监听label
68 | self.stateLabel.userInteractionEnabled = YES;
69 | [self.stateLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(stateLabelClick)]];
70 | }
71 |
72 | - (void)placeSubviews
73 | {
74 | [super placeSubviews];
75 |
76 | if (self.stateLabel.constraints.count) return;
77 |
78 | // 状态标签
79 | self.stateLabel.frame = self.bounds;
80 | }
81 |
82 | - (void)setState:(MJRefreshState)state
83 | {
84 | MJRefreshCheckState
85 |
86 | if (self.isRefreshingTitleHidden && state == MJRefreshStateRefreshing) {
87 | self.stateLabel.text = nil;
88 | } else {
89 | self.stateLabel.text = self.stateTitles[@(state)];
90 | }
91 | }
92 | @end
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshBackGifFooter.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshBackStateFooter.h"
10 |
11 | @interface MJRefreshBackGifFooter : MJRefreshBackStateFooter
12 | @property (weak, nonatomic, readonly) UIImageView *gifView;
13 |
14 | /** 设置state状态下的动画图片images 动画持续时间duration*/
15 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state;
16 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state;
17 | @end
18 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Back/MJRefreshBackGifFooter.m:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshBackGifFooter.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshBackGifFooter.h"
10 |
11 | @interface MJRefreshBackGifFooter()
12 | {
13 | __unsafe_unretained UIImageView *_gifView;
14 | }
15 | /** 所有状态对应的动画图片 */
16 | @property (strong, nonatomic) NSMutableDictionary *stateImages;
17 | /** 所有状态对应的动画时间 */
18 | @property (strong, nonatomic) NSMutableDictionary *stateDurations;
19 | @end
20 |
21 | @implementation MJRefreshBackGifFooter
22 | #pragma mark - 懒加载
23 | - (UIImageView *)gifView
24 | {
25 | if (!_gifView) {
26 | UIImageView *gifView = [[UIImageView alloc] init];
27 | [self addSubview:_gifView = gifView];
28 | }
29 | return _gifView;
30 | }
31 |
32 | - (NSMutableDictionary *)stateImages
33 | {
34 | if (!_stateImages) {
35 | self.stateImages = [NSMutableDictionary dictionary];
36 | }
37 | return _stateImages;
38 | }
39 |
40 | - (NSMutableDictionary *)stateDurations
41 | {
42 | if (!_stateDurations) {
43 | self.stateDurations = [NSMutableDictionary dictionary];
44 | }
45 | return _stateDurations;
46 | }
47 |
48 | #pragma mark - 公共方法
49 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state
50 | {
51 | if (images == nil) return;
52 |
53 | self.stateImages[@(state)] = images;
54 | self.stateDurations[@(state)] = @(duration);
55 |
56 | /* 根据图片设置控件的高度 */
57 | UIImage *image = [images firstObject];
58 | if (image.size.height > self.mj_h) {
59 | self.mj_h = image.size.height;
60 | }
61 | }
62 |
63 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state
64 | {
65 | [self setImages:images duration:images.count * 0.1 forState:state];
66 | }
67 |
68 | #pragma mark - 实现父类的方法
69 | - (void)prepare
70 | {
71 | [super prepare];
72 |
73 | // 初始化间距
74 | self.labelLeftInset = 20;
75 | }
76 |
77 | - (void)setPullingPercent:(CGFloat)pullingPercent
78 | {
79 | [super setPullingPercent:pullingPercent];
80 | NSArray *images = self.stateImages[@(MJRefreshStateIdle)];
81 | if (self.state != MJRefreshStateIdle || images.count == 0) return;
82 | [self.gifView stopAnimating];
83 | NSUInteger index = images.count * pullingPercent;
84 | if (index >= images.count) index = images.count - 1;
85 | self.gifView.image = images[index];
86 | }
87 |
88 | - (void)placeSubviews
89 | {
90 | [super placeSubviews];
91 |
92 | if (self.gifView.constraints.count) return;
93 |
94 | self.gifView.frame = self.bounds;
95 | if (self.stateLabel.hidden) {
96 | self.gifView.contentMode = UIViewContentModeCenter;
97 | } else {
98 | self.gifView.contentMode = UIViewContentModeRight;
99 | self.gifView.mj_w = self.mj_w * 0.5 - self.labelLeftInset - self.stateLabel.mj_textWith * 0.5;
100 | }
101 | }
102 |
103 | - (void)setState:(MJRefreshState)state
104 | {
105 | MJRefreshCheckState
106 |
107 | // 根据状态做事情
108 | if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) {
109 | NSArray *images = self.stateImages[@(state)];
110 | if (images.count == 0) return;
111 |
112 | self.gifView.hidden = NO;
113 | [self.gifView stopAnimating];
114 | if (images.count == 1) { // 单张图片
115 | self.gifView.image = [images lastObject];
116 | } else { // 多张图片
117 | self.gifView.animationImages = images;
118 | self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue];
119 | [self.gifView startAnimating];
120 | }
121 | } else if (state == MJRefreshStateIdle) {
122 | self.gifView.hidden = NO;
123 | } else if (state == MJRefreshStateNoMoreData) {
124 | self.gifView.hidden = YES;
125 | }
126 | }
127 | @end
128 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshBackNormalFooter.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshBackStateFooter.h"
10 |
11 | @interface MJRefreshBackNormalFooter : MJRefreshBackStateFooter
12 | @property (weak, nonatomic, readonly) UIImageView *arrowView;
13 | /** 菊花的样式 */
14 | @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle;
15 | @end
16 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Back/MJRefreshBackNormalFooter.m:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshBackNormalFooter.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshBackNormalFooter.h"
10 | #import "NSBundle+MJRefresh.h"
11 |
12 | @interface MJRefreshBackNormalFooter()
13 | {
14 | __unsafe_unretained UIImageView *_arrowView;
15 | }
16 | @property (weak, nonatomic) UIActivityIndicatorView *loadingView;
17 | @end
18 |
19 | @implementation MJRefreshBackNormalFooter
20 | #pragma mark - 懒加载子控件
21 | - (UIImageView *)arrowView
22 | {
23 | if (!_arrowView) {
24 | UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]];
25 | [self addSubview:_arrowView = arrowView];
26 | }
27 | return _arrowView;
28 | }
29 |
30 |
31 | - (UIActivityIndicatorView *)loadingView
32 | {
33 | if (!_loadingView) {
34 | UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle];
35 | loadingView.hidesWhenStopped = YES;
36 | [self addSubview:_loadingView = loadingView];
37 | }
38 | return _loadingView;
39 | }
40 |
41 | - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle
42 | {
43 | _activityIndicatorViewStyle = activityIndicatorViewStyle;
44 |
45 | self.loadingView = nil;
46 | [self setNeedsLayout];
47 | }
48 | #pragma mark - 重写父类的方法
49 | - (void)prepare
50 | {
51 | [super prepare];
52 |
53 | self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
54 | }
55 |
56 | - (void)placeSubviews
57 | {
58 | [super placeSubviews];
59 |
60 | // 箭头的中心点
61 | CGFloat arrowCenterX = self.mj_w * 0.5;
62 | if (!self.stateLabel.hidden) {
63 | arrowCenterX -= self.labelLeftInset + self.stateLabel.mj_textWith * 0.5;
64 | }
65 | CGFloat arrowCenterY = self.mj_h * 0.5;
66 | CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY);
67 |
68 | // 箭头
69 | if (self.arrowView.constraints.count == 0) {
70 | self.arrowView.mj_size = self.arrowView.image.size;
71 | self.arrowView.center = arrowCenter;
72 | }
73 |
74 | // 圈圈
75 | if (self.loadingView.constraints.count == 0) {
76 | self.loadingView.center = arrowCenter;
77 | }
78 |
79 | self.arrowView.tintColor = self.stateLabel.textColor;
80 | }
81 |
82 | - (void)setState:(MJRefreshState)state
83 | {
84 | MJRefreshCheckState
85 |
86 | // 根据状态做事情
87 | if (state == MJRefreshStateIdle) {
88 | if (oldState == MJRefreshStateRefreshing) {
89 | self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI);
90 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{
91 | self.loadingView.alpha = 0.0;
92 | } completion:^(BOOL finished) {
93 | // 防止动画结束后,状态已经不是MJRefreshStateIdle
94 | if (state != MJRefreshStateIdle) return;
95 |
96 | self.loadingView.alpha = 1.0;
97 | [self.loadingView stopAnimating];
98 |
99 | self.arrowView.hidden = NO;
100 | }];
101 | } else {
102 | self.arrowView.hidden = NO;
103 | [self.loadingView stopAnimating];
104 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{
105 | self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI);
106 | }];
107 | }
108 | } else if (state == MJRefreshStatePulling) {
109 | self.arrowView.hidden = NO;
110 | [self.loadingView stopAnimating];
111 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{
112 | self.arrowView.transform = CGAffineTransformIdentity;
113 | }];
114 | } else if (state == MJRefreshStateRefreshing) {
115 | self.arrowView.hidden = YES;
116 | [self.loadingView startAnimating];
117 | } else if (state == MJRefreshStateNoMoreData) {
118 | self.arrowView.hidden = YES;
119 | [self.loadingView stopAnimating];
120 | }
121 | }
122 |
123 | @end
124 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshBackStateFooter.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/6/13.
6 | // Copyright © 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshBackFooter.h"
10 |
11 | @interface MJRefreshBackStateFooter : MJRefreshBackFooter
12 | /** 文字距离圈圈、箭头的距离 */
13 | @property (assign, nonatomic) CGFloat labelLeftInset;
14 | /** 显示刷新状态的label */
15 | @property (weak, nonatomic, readonly) UILabel *stateLabel;
16 | /** 设置state状态下的文字 */
17 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state;
18 |
19 | /** 获取state状态下的title */
20 | - (NSString *)titleForState:(MJRefreshState)state;
21 | @end
22 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Footer/Back/MJRefreshBackStateFooter.m:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshBackStateFooter.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/6/13.
6 | // Copyright © 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshBackStateFooter.h"
10 |
11 | @interface MJRefreshBackStateFooter()
12 | {
13 | /** 显示刷新状态的label */
14 | __unsafe_unretained UILabel *_stateLabel;
15 | }
16 | /** 所有状态对应的文字 */
17 | @property (strong, nonatomic) NSMutableDictionary *stateTitles;
18 | @end
19 |
20 | @implementation MJRefreshBackStateFooter
21 | #pragma mark - 懒加载
22 | - (NSMutableDictionary *)stateTitles
23 | {
24 | if (!_stateTitles) {
25 | self.stateTitles = [NSMutableDictionary dictionary];
26 | }
27 | return _stateTitles;
28 | }
29 |
30 | - (UILabel *)stateLabel
31 | {
32 | if (!_stateLabel) {
33 | [self addSubview:_stateLabel = [UILabel mj_label]];
34 | }
35 | return _stateLabel;
36 | }
37 |
38 | #pragma mark - 公共方法
39 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state
40 | {
41 | if (title == nil) return;
42 | self.stateTitles[@(state)] = title;
43 | self.stateLabel.text = self.stateTitles[@(self.state)];
44 | }
45 |
46 | - (NSString *)titleForState:(MJRefreshState)state {
47 | return self.stateTitles[@(state)];
48 | }
49 |
50 | #pragma mark - 重写父类的方法
51 | - (void)prepare
52 | {
53 | [super prepare];
54 |
55 | // 初始化间距
56 | self.labelLeftInset = MJRefreshLabelLeftInset;
57 |
58 | // 初始化文字
59 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterIdleText] forState:MJRefreshStateIdle];
60 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterPullingText] forState:MJRefreshStatePulling];
61 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterRefreshingText] forState:MJRefreshStateRefreshing];
62 | [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterNoMoreDataText] forState:MJRefreshStateNoMoreData];
63 | }
64 |
65 | - (void)placeSubviews
66 | {
67 | [super placeSubviews];
68 |
69 | if (self.stateLabel.constraints.count) return;
70 |
71 | // 状态标签
72 | self.stateLabel.frame = self.bounds;
73 | }
74 |
75 | - (void)setState:(MJRefreshState)state
76 | {
77 | MJRefreshCheckState
78 |
79 | // 设置状态文字
80 | self.stateLabel.text = self.stateTitles[@(state)];
81 | }
82 | @end
83 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Header/MJRefreshGifHeader.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshGifHeader.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshStateHeader.h"
10 |
11 | @interface MJRefreshGifHeader : MJRefreshStateHeader
12 | @property (weak, nonatomic, readonly) UIImageView *gifView;
13 |
14 | /** 设置state状态下的动画图片images 动画持续时间duration*/
15 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state;
16 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state;
17 | @end
18 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Header/MJRefreshGifHeader.m:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshGifHeader.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshGifHeader.h"
10 |
11 | @interface MJRefreshGifHeader()
12 | {
13 | __unsafe_unretained UIImageView *_gifView;
14 | }
15 | /** 所有状态对应的动画图片 */
16 | @property (strong, nonatomic) NSMutableDictionary *stateImages;
17 | /** 所有状态对应的动画时间 */
18 | @property (strong, nonatomic) NSMutableDictionary *stateDurations;
19 | @end
20 |
21 | @implementation MJRefreshGifHeader
22 | #pragma mark - 懒加载
23 | - (UIImageView *)gifView
24 | {
25 | if (!_gifView) {
26 | UIImageView *gifView = [[UIImageView alloc] init];
27 | [self addSubview:_gifView = gifView];
28 | }
29 | return _gifView;
30 | }
31 |
32 | - (NSMutableDictionary *)stateImages
33 | {
34 | if (!_stateImages) {
35 | self.stateImages = [NSMutableDictionary dictionary];
36 | }
37 | return _stateImages;
38 | }
39 |
40 | - (NSMutableDictionary *)stateDurations
41 | {
42 | if (!_stateDurations) {
43 | self.stateDurations = [NSMutableDictionary dictionary];
44 | }
45 | return _stateDurations;
46 | }
47 |
48 | #pragma mark - 公共方法
49 | - (void)setImages:(NSArray *)images duration:(NSTimeInterval)duration forState:(MJRefreshState)state
50 | {
51 | if (images == nil) return;
52 |
53 | self.stateImages[@(state)] = images;
54 | self.stateDurations[@(state)] = @(duration);
55 |
56 | /* 根据图片设置控件的高度 */
57 | UIImage *image = [images firstObject];
58 | if (image.size.height > self.mj_h) {
59 | self.mj_h = image.size.height;
60 | }
61 | }
62 |
63 | - (void)setImages:(NSArray *)images forState:(MJRefreshState)state
64 | {
65 | [self setImages:images duration:images.count * 0.1 forState:state];
66 | }
67 |
68 | #pragma mark - 实现父类的方法
69 | - (void)prepare
70 | {
71 | [super prepare];
72 |
73 | // 初始化间距
74 | self.labelLeftInset = 20;
75 | }
76 |
77 | - (void)setPullingPercent:(CGFloat)pullingPercent
78 | {
79 | [super setPullingPercent:pullingPercent];
80 | NSArray *images = self.stateImages[@(MJRefreshStateIdle)];
81 | if (self.state != MJRefreshStateIdle || images.count == 0) return;
82 | // 停止动画
83 | [self.gifView stopAnimating];
84 | // 设置当前需要显示的图片
85 | NSUInteger index = images.count * pullingPercent;
86 | if (index >= images.count) index = images.count - 1;
87 | self.gifView.image = images[index];
88 | }
89 |
90 | - (void)placeSubviews
91 | {
92 | [super placeSubviews];
93 |
94 | if (self.gifView.constraints.count) return;
95 |
96 | self.gifView.frame = self.bounds;
97 | if (self.stateLabel.hidden && self.lastUpdatedTimeLabel.hidden) {
98 | self.gifView.contentMode = UIViewContentModeCenter;
99 | } else {
100 | self.gifView.contentMode = UIViewContentModeRight;
101 |
102 | CGFloat stateWidth = self.stateLabel.mj_textWith;
103 | CGFloat timeWidth = 0.0;
104 | if (!self.lastUpdatedTimeLabel.hidden) {
105 | timeWidth = self.lastUpdatedTimeLabel.mj_textWith;
106 | }
107 | CGFloat textWidth = MAX(stateWidth, timeWidth);
108 | self.gifView.mj_w = self.mj_w * 0.5 - textWidth * 0.5 - self.labelLeftInset;
109 | }
110 | }
111 |
112 | - (void)setState:(MJRefreshState)state
113 | {
114 | MJRefreshCheckState
115 |
116 | // 根据状态做事情
117 | if (state == MJRefreshStatePulling || state == MJRefreshStateRefreshing) {
118 | NSArray *images = self.stateImages[@(state)];
119 | if (images.count == 0) return;
120 |
121 | [self.gifView stopAnimating];
122 | if (images.count == 1) { // 单张图片
123 | self.gifView.image = [images lastObject];
124 | } else { // 多张图片
125 | self.gifView.animationImages = images;
126 | self.gifView.animationDuration = [self.stateDurations[@(state)] doubleValue];
127 | [self.gifView startAnimating];
128 | }
129 | } else if (state == MJRefreshStateIdle) {
130 | [self.gifView stopAnimating];
131 | }
132 | }
133 | @end
134 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Header/MJRefreshNormalHeader.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshNormalHeader.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshStateHeader.h"
10 |
11 | @interface MJRefreshNormalHeader : MJRefreshStateHeader
12 | @property (weak, nonatomic, readonly) UIImageView *arrowView;
13 | /** 菊花的样式 */
14 | @property (assign, nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle;
15 | @end
16 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Header/MJRefreshNormalHeader.m:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshNormalHeader.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshNormalHeader.h"
10 | #import "NSBundle+MJRefresh.h"
11 |
12 | @interface MJRefreshNormalHeader()
13 | {
14 | __unsafe_unretained UIImageView *_arrowView;
15 | }
16 | @property (weak, nonatomic) UIActivityIndicatorView *loadingView;
17 | @end
18 |
19 | @implementation MJRefreshNormalHeader
20 | #pragma mark - 懒加载子控件
21 | - (UIImageView *)arrowView
22 | {
23 | if (!_arrowView) {
24 | UIImageView *arrowView = [[UIImageView alloc] initWithImage:[NSBundle mj_arrowImage]];
25 | [self addSubview:_arrowView = arrowView];
26 | }
27 | return _arrowView;
28 | }
29 |
30 | - (UIActivityIndicatorView *)loadingView
31 | {
32 | if (!_loadingView) {
33 | UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle];
34 | loadingView.hidesWhenStopped = YES;
35 | [self addSubview:_loadingView = loadingView];
36 | }
37 | return _loadingView;
38 | }
39 |
40 | #pragma mark - 公共方法
41 | - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle
42 | {
43 | _activityIndicatorViewStyle = activityIndicatorViewStyle;
44 |
45 | self.loadingView = nil;
46 | [self setNeedsLayout];
47 | }
48 |
49 | #pragma mark - 重写父类的方法
50 | - (void)prepare
51 | {
52 | [super prepare];
53 |
54 | self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
55 | }
56 |
57 | - (void)placeSubviews
58 | {
59 | [super placeSubviews];
60 |
61 | // 箭头的中心点
62 | CGFloat arrowCenterX = self.mj_w * 0.5;
63 | if (!self.stateLabel.hidden) {
64 | CGFloat stateWidth = self.stateLabel.mj_textWith;
65 | CGFloat timeWidth = 0.0;
66 | if (!self.lastUpdatedTimeLabel.hidden) {
67 | timeWidth = self.lastUpdatedTimeLabel.mj_textWith;
68 | }
69 | CGFloat textWidth = MAX(stateWidth, timeWidth);
70 | arrowCenterX -= textWidth / 2 + self.labelLeftInset;
71 | }
72 | CGFloat arrowCenterY = self.mj_h * 0.5;
73 | CGPoint arrowCenter = CGPointMake(arrowCenterX, arrowCenterY);
74 |
75 | // 箭头
76 | if (self.arrowView.constraints.count == 0) {
77 | self.arrowView.mj_size = self.arrowView.image.size;
78 | self.arrowView.center = arrowCenter;
79 | }
80 |
81 | // 圈圈
82 | if (self.loadingView.constraints.count == 0) {
83 | self.loadingView.center = arrowCenter;
84 | }
85 |
86 | self.arrowView.tintColor = self.stateLabel.textColor;
87 | }
88 |
89 | - (void)setState:(MJRefreshState)state
90 | {
91 | MJRefreshCheckState
92 |
93 | // 根据状态做事情
94 | if (state == MJRefreshStateIdle) {
95 | if (oldState == MJRefreshStateRefreshing) {
96 | self.arrowView.transform = CGAffineTransformIdentity;
97 |
98 | [UIView animateWithDuration:MJRefreshSlowAnimationDuration animations:^{
99 | self.loadingView.alpha = 0.0;
100 | } completion:^(BOOL finished) {
101 | // 如果执行完动画发现不是idle状态,就直接返回,进入其他状态
102 | if (self.state != MJRefreshStateIdle) return;
103 |
104 | self.loadingView.alpha = 1.0;
105 | [self.loadingView stopAnimating];
106 | self.arrowView.hidden = NO;
107 | }];
108 | } else {
109 | [self.loadingView stopAnimating];
110 | self.arrowView.hidden = NO;
111 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{
112 | self.arrowView.transform = CGAffineTransformIdentity;
113 | }];
114 | }
115 | } else if (state == MJRefreshStatePulling) {
116 | [self.loadingView stopAnimating];
117 | self.arrowView.hidden = NO;
118 | [UIView animateWithDuration:MJRefreshFastAnimationDuration animations:^{
119 | self.arrowView.transform = CGAffineTransformMakeRotation(0.000001 - M_PI);
120 | }];
121 | } else if (state == MJRefreshStateRefreshing) {
122 | self.loadingView.alpha = 1.0; // 防止refreshing -> idle的动画完毕动作没有被执行
123 | [self.loadingView startAnimating];
124 | self.arrowView.hidden = YES;
125 | }
126 | }
127 | @end
128 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/Custom/Header/MJRefreshStateHeader.h:
--------------------------------------------------------------------------------
1 | //
2 | // MJRefreshStateHeader.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 15/4/24.
6 | // Copyright (c) 2015年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "MJRefreshHeader.h"
10 |
11 | @interface MJRefreshStateHeader : MJRefreshHeader
12 | #pragma mark - 刷新时间相关
13 | /** 利用这个block来决定显示的更新时间文字 */
14 | @property (copy, nonatomic) NSString *(^lastUpdatedTimeText)(NSDate *lastUpdatedTime);
15 | /** 显示上一次刷新时间的label */
16 | @property (weak, nonatomic, readonly) UILabel *lastUpdatedTimeLabel;
17 |
18 | #pragma mark - 状态相关
19 | /** 文字距离圈圈、箭头的距离 */
20 | @property (assign, nonatomic) CGFloat labelLeftInset;
21 | /** 显示刷新状态的label */
22 | @property (weak, nonatomic, readonly) UILabel *stateLabel;
23 | /** 设置state状态下的文字 */
24 | - (void)setTitle:(NSString *)title forState:(MJRefreshState)state;
25 | @end
26 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/MJRefresh.bundle/arrow@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pujiaxin33/JXPageListView/804e26282202bea43a448b6aafc924958922e139/JXPageListView/Example/MJRefresh/MJRefresh.bundle/arrow@2x.png
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/MJRefresh.bundle/en.lproj/Localizable.strings:
--------------------------------------------------------------------------------
1 | "MJRefreshHeaderIdleText" = "Pull down to refresh";
2 | "MJRefreshHeaderPullingText" = "Release to refresh";
3 | "MJRefreshHeaderRefreshingText" = "Loading...";
4 |
5 | "MJRefreshAutoFooterIdleText" = "Tap or pull up to load more";
6 | "MJRefreshAutoFooterRefreshingText" = "Loading...";
7 | "MJRefreshAutoFooterNoMoreDataText" = "No more data";
8 |
9 | "MJRefreshBackFooterIdleText" = "Pull up to load more";
10 | "MJRefreshBackFooterPullingText" = "Release to load more.";
11 | "MJRefreshBackFooterRefreshingText" = "Loading...";
12 | "MJRefreshBackFooterNoMoreDataText" = "No more data";
13 |
14 | "MJRefreshHeaderLastTimeText" = "Last updated: ";
15 | "MJRefreshHeaderDateTodayText" = "Today";
16 | "MJRefreshHeaderNoneLastDateText" = "No record";
17 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pujiaxin33/JXPageListView/804e26282202bea43a448b6aafc924958922e139/JXPageListView/Example/MJRefresh/MJRefresh.bundle/zh-Hans.lproj/Localizable.strings
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/MJRefresh.bundle/zh-Hant.lproj/Localizable.strings:
--------------------------------------------------------------------------------
1 | "MJRefreshHeaderIdleText" = "下拉可以刷新";
2 | "MJRefreshHeaderPullingText" = "鬆開立即刷新";
3 | "MJRefreshHeaderRefreshingText" = "正在刷新數據中...";
4 |
5 | "MJRefreshAutoFooterIdleText" = "點擊或上拉加載更多";
6 | "MJRefreshAutoFooterRefreshingText" = "正在加載更多的數據...";
7 | "MJRefreshAutoFooterNoMoreDataText" = "已經全部加載完畢";
8 |
9 | "MJRefreshBackFooterIdleText" = "上拉可以加載更多";
10 | "MJRefreshBackFooterPullingText" = "鬆開立即加載更多";
11 | "MJRefreshBackFooterRefreshingText" = "正在加載更多的數據...";
12 | "MJRefreshBackFooterNoMoreDataText" = "已經全部加載完畢";
13 |
14 | "MJRefreshHeaderLastTimeText" = "最後更新:";
15 | "MJRefreshHeaderDateTodayText" = "今天";
16 | "MJRefreshHeaderNoneLastDateText" = "無記錄";
17 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/MJRefresh.h:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 |
4 | #import "UIScrollView+MJRefresh.h"
5 | #import "UIScrollView+MJExtension.h"
6 | #import "UIView+MJExtension.h"
7 |
8 | #import "MJRefreshNormalHeader.h"
9 | #import "MJRefreshGifHeader.h"
10 |
11 | #import "MJRefreshBackNormalFooter.h"
12 | #import "MJRefreshBackGifFooter.h"
13 | #import "MJRefreshAutoNormalFooter.h"
14 | #import "MJRefreshAutoGifFooter.h"
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/MJRefreshConst.h:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | #import
4 | #import
5 |
6 | // 弱引用
7 | #define MJWeakSelf __weak typeof(self) weakSelf = self;
8 |
9 | // 日志输出
10 | #ifdef DEBUG
11 | #define MJRefreshLog(...) NSLog(__VA_ARGS__)
12 | #else
13 | #define MJRefreshLog(...)
14 | #endif
15 |
16 | // 过期提醒
17 | #define MJRefreshDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead)
18 |
19 | // 运行时objc_msgSend
20 | #define MJRefreshMsgSend(...) ((void (*)(void *, SEL, UIView *))objc_msgSend)(__VA_ARGS__)
21 | #define MJRefreshMsgTarget(target) (__bridge void *)(target)
22 |
23 | // RGB颜色
24 | #define MJRefreshColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
25 |
26 | // 文字颜色
27 | #define MJRefreshLabelTextColor MJRefreshColor(90, 90, 90)
28 |
29 | // 字体大小
30 | #define MJRefreshLabelFont [UIFont boldSystemFontOfSize:14]
31 |
32 | // 常量
33 | UIKIT_EXTERN const CGFloat MJRefreshLabelLeftInset;
34 | UIKIT_EXTERN const CGFloat MJRefreshHeaderHeight;
35 | UIKIT_EXTERN const CGFloat MJRefreshFooterHeight;
36 | UIKIT_EXTERN const CGFloat MJRefreshFastAnimationDuration;
37 | UIKIT_EXTERN const CGFloat MJRefreshSlowAnimationDuration;
38 |
39 | UIKIT_EXTERN NSString *const MJRefreshKeyPathContentOffset;
40 | UIKIT_EXTERN NSString *const MJRefreshKeyPathContentSize;
41 | UIKIT_EXTERN NSString *const MJRefreshKeyPathContentInset;
42 | UIKIT_EXTERN NSString *const MJRefreshKeyPathPanState;
43 |
44 | UIKIT_EXTERN NSString *const MJRefreshHeaderLastUpdatedTimeKey;
45 |
46 | UIKIT_EXTERN NSString *const MJRefreshHeaderIdleText;
47 | UIKIT_EXTERN NSString *const MJRefreshHeaderPullingText;
48 | UIKIT_EXTERN NSString *const MJRefreshHeaderRefreshingText;
49 |
50 | UIKIT_EXTERN NSString *const MJRefreshAutoFooterIdleText;
51 | UIKIT_EXTERN NSString *const MJRefreshAutoFooterRefreshingText;
52 | UIKIT_EXTERN NSString *const MJRefreshAutoFooterNoMoreDataText;
53 |
54 | UIKIT_EXTERN NSString *const MJRefreshBackFooterIdleText;
55 | UIKIT_EXTERN NSString *const MJRefreshBackFooterPullingText;
56 | UIKIT_EXTERN NSString *const MJRefreshBackFooterRefreshingText;
57 | UIKIT_EXTERN NSString *const MJRefreshBackFooterNoMoreDataText;
58 |
59 | UIKIT_EXTERN NSString *const MJRefreshHeaderLastTimeText;
60 | UIKIT_EXTERN NSString *const MJRefreshHeaderDateTodayText;
61 | UIKIT_EXTERN NSString *const MJRefreshHeaderNoneLastDateText;
62 |
63 | // 状态检查
64 | #define MJRefreshCheckState \
65 | MJRefreshState oldState = self.state; \
66 | if (state == oldState) return; \
67 | [super setState:state];
68 |
69 | // 异步主线程执行,不强持有Self
70 | #define MJRefreshDispatchAsyncOnMainQueue(x) \
71 | __weak typeof(self) weakSelf = self; \
72 | dispatch_async(dispatch_get_main_queue(), ^{ \
73 | typeof(weakSelf) self = weakSelf; \
74 | {x} \
75 | });
76 |
77 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/MJRefreshConst.m:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | #import
4 |
5 | const CGFloat MJRefreshLabelLeftInset = 25;
6 | const CGFloat MJRefreshHeaderHeight = 54.0;
7 | const CGFloat MJRefreshFooterHeight = 44.0;
8 | const CGFloat MJRefreshFastAnimationDuration = 0.25;
9 | const CGFloat MJRefreshSlowAnimationDuration = 0.4;
10 |
11 | NSString *const MJRefreshKeyPathContentOffset = @"contentOffset";
12 | NSString *const MJRefreshKeyPathContentInset = @"contentInset";
13 | NSString *const MJRefreshKeyPathContentSize = @"contentSize";
14 | NSString *const MJRefreshKeyPathPanState = @"state";
15 |
16 | NSString *const MJRefreshHeaderLastUpdatedTimeKey = @"MJRefreshHeaderLastUpdatedTimeKey";
17 |
18 | NSString *const MJRefreshHeaderIdleText = @"MJRefreshHeaderIdleText";
19 | NSString *const MJRefreshHeaderPullingText = @"MJRefreshHeaderPullingText";
20 | NSString *const MJRefreshHeaderRefreshingText = @"MJRefreshHeaderRefreshingText";
21 |
22 | NSString *const MJRefreshAutoFooterIdleText = @"MJRefreshAutoFooterIdleText";
23 | NSString *const MJRefreshAutoFooterRefreshingText = @"MJRefreshAutoFooterRefreshingText";
24 | NSString *const MJRefreshAutoFooterNoMoreDataText = @"MJRefreshAutoFooterNoMoreDataText";
25 |
26 | NSString *const MJRefreshBackFooterIdleText = @"MJRefreshBackFooterIdleText";
27 | NSString *const MJRefreshBackFooterPullingText = @"MJRefreshBackFooterPullingText";
28 | NSString *const MJRefreshBackFooterRefreshingText = @"MJRefreshBackFooterRefreshingText";
29 | NSString *const MJRefreshBackFooterNoMoreDataText = @"MJRefreshBackFooterNoMoreDataText";
30 |
31 | NSString *const MJRefreshHeaderLastTimeText = @"MJRefreshHeaderLastTimeText";
32 | NSString *const MJRefreshHeaderDateTodayText = @"MJRefreshHeaderDateTodayText";
33 | NSString *const MJRefreshHeaderNoneLastDateText = @"MJRefreshHeaderNoneLastDateText";
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/NSBundle+MJRefresh.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSBundle+MJRefresh.h
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 16/6/13.
6 | // Copyright © 2016年 小码哥. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NSBundle (MJRefresh)
12 | + (instancetype)mj_refreshBundle;
13 | + (UIImage *)mj_arrowImage;
14 | + (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value;
15 | + (NSString *)mj_localizedStringForKey:(NSString *)key;
16 | @end
17 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/NSBundle+MJRefresh.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSBundle+MJRefresh.m
3 | // MJRefreshExample
4 | //
5 | // Created by MJ Lee on 16/6/13.
6 | // Copyright © 2016年 小码哥. All rights reserved.
7 | //
8 |
9 | #import "NSBundle+MJRefresh.h"
10 | #import "MJRefreshComponent.h"
11 |
12 | @implementation NSBundle (MJRefresh)
13 | + (instancetype)mj_refreshBundle
14 | {
15 | static NSBundle *refreshBundle = nil;
16 | if (refreshBundle == nil) {
17 | // 这里不使用mainBundle是为了适配pod 1.x和0.x
18 | refreshBundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:[MJRefreshComponent class]] pathForResource:@"MJRefresh" ofType:@"bundle"]];
19 | }
20 | return refreshBundle;
21 | }
22 |
23 | + (UIImage *)mj_arrowImage
24 | {
25 | static UIImage *arrowImage = nil;
26 | if (arrowImage == nil) {
27 | arrowImage = [[UIImage imageWithContentsOfFile:[[self mj_refreshBundle] pathForResource:@"arrow@2x" ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
28 | }
29 | return arrowImage;
30 | }
31 |
32 | + (NSString *)mj_localizedStringForKey:(NSString *)key
33 | {
34 | return [self mj_localizedStringForKey:key value:nil];
35 | }
36 |
37 | + (NSString *)mj_localizedStringForKey:(NSString *)key value:(NSString *)value
38 | {
39 | static NSBundle *bundle = nil;
40 | if (bundle == nil) {
41 | // (iOS获取的语言字符串比较不稳定)目前框架只处理en、zh-Hans、zh-Hant三种情况,其他按照系统默认处理
42 | NSString *language = [NSLocale preferredLanguages].firstObject;
43 | if ([language hasPrefix:@"en"]) {
44 | language = @"en";
45 | } else if ([language hasPrefix:@"zh"]) {
46 | if ([language rangeOfString:@"Hans"].location != NSNotFound) {
47 | language = @"zh-Hans"; // 简体中文
48 | } else { // zh-Hant\zh-HK\zh-TW
49 | language = @"zh-Hant"; // 繁體中文
50 | }
51 | } else {
52 | language = @"en";
53 | }
54 |
55 | // 从MJRefresh.bundle中查找资源
56 | bundle = [NSBundle bundleWithPath:[[NSBundle mj_refreshBundle] pathForResource:language ofType:@"lproj"]];
57 | }
58 | value = [bundle localizedStringForKey:key value:value table:nil];
59 | return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil];
60 | }
61 | @end
62 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/UIScrollView+MJExtension.h:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | // UIScrollView+Extension.h
4 | // MJRefreshExample
5 | //
6 | // Created by MJ Lee on 14-5-28.
7 | // Copyright (c) 2014年 小码哥. All rights reserved.
8 | //
9 |
10 | #import
11 |
12 | @interface UIScrollView (MJExtension)
13 | @property (readonly, nonatomic) UIEdgeInsets mj_inset;
14 |
15 | @property (assign, nonatomic) CGFloat mj_insetT;
16 | @property (assign, nonatomic) CGFloat mj_insetB;
17 | @property (assign, nonatomic) CGFloat mj_insetL;
18 | @property (assign, nonatomic) CGFloat mj_insetR;
19 |
20 | @property (assign, nonatomic) CGFloat mj_offsetX;
21 | @property (assign, nonatomic) CGFloat mj_offsetY;
22 |
23 | @property (assign, nonatomic) CGFloat mj_contentW;
24 | @property (assign, nonatomic) CGFloat mj_contentH;
25 | @end
26 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/UIScrollView+MJExtension.m:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | // UIScrollView+Extension.m
4 | // MJRefreshExample
5 | //
6 | // Created by MJ Lee on 14-5-28.
7 | // Copyright (c) 2014年 小码哥. All rights reserved.
8 | //
9 |
10 | #import "UIScrollView+MJExtension.h"
11 | #import
12 |
13 | #pragma clang diagnostic push
14 | #pragma clang diagnostic ignored "-Wunguarded-availability-new"
15 |
16 | @implementation UIScrollView (MJExtension)
17 |
18 | static BOOL respondsToAdjustedContentInset_;
19 |
20 | + (void)initialize
21 | {
22 | static dispatch_once_t onceToken;
23 | dispatch_once(&onceToken, ^{
24 | respondsToAdjustedContentInset_ = [self respondsToSelector:@selector(adjustedContentInset)];
25 | });
26 | }
27 |
28 | - (UIEdgeInsets)mj_inset
29 | {
30 | #ifdef __IPHONE_11_0
31 | if (respondsToAdjustedContentInset_) {
32 | return self.adjustedContentInset;
33 | }
34 | #endif
35 | return self.contentInset;
36 | }
37 |
38 | - (void)setMj_insetT:(CGFloat)mj_insetT
39 | {
40 | UIEdgeInsets inset = self.contentInset;
41 | inset.top = mj_insetT;
42 | #ifdef __IPHONE_11_0
43 | if (respondsToAdjustedContentInset_) {
44 | inset.top -= (self.adjustedContentInset.top - self.contentInset.top);
45 | }
46 | #endif
47 | self.contentInset = inset;
48 | }
49 |
50 | - (CGFloat)mj_insetT
51 | {
52 | return self.mj_inset.top;
53 | }
54 |
55 | - (void)setMj_insetB:(CGFloat)mj_insetB
56 | {
57 | UIEdgeInsets inset = self.contentInset;
58 | inset.bottom = mj_insetB;
59 | #ifdef __IPHONE_11_0
60 | if (respondsToAdjustedContentInset_) {
61 | inset.bottom -= (self.adjustedContentInset.bottom - self.contentInset.bottom);
62 | }
63 | #endif
64 | self.contentInset = inset;
65 | }
66 |
67 | - (CGFloat)mj_insetB
68 | {
69 | return self.mj_inset.bottom;
70 | }
71 |
72 | - (void)setMj_insetL:(CGFloat)mj_insetL
73 | {
74 | UIEdgeInsets inset = self.contentInset;
75 | inset.left = mj_insetL;
76 | #ifdef __IPHONE_11_0
77 | if (respondsToAdjustedContentInset_) {
78 | inset.left -= (self.adjustedContentInset.left - self.contentInset.left);
79 | }
80 | #endif
81 | self.contentInset = inset;
82 | }
83 |
84 | - (CGFloat)mj_insetL
85 | {
86 | return self.mj_inset.left;
87 | }
88 |
89 | - (void)setMj_insetR:(CGFloat)mj_insetR
90 | {
91 | UIEdgeInsets inset = self.contentInset;
92 | inset.right = mj_insetR;
93 | #ifdef __IPHONE_11_0
94 | if (respondsToAdjustedContentInset_) {
95 | inset.right -= (self.adjustedContentInset.right - self.contentInset.right);
96 | }
97 | #endif
98 | self.contentInset = inset;
99 | }
100 |
101 | - (CGFloat)mj_insetR
102 | {
103 | return self.mj_inset.right;
104 | }
105 |
106 | - (void)setMj_offsetX:(CGFloat)mj_offsetX
107 | {
108 | CGPoint offset = self.contentOffset;
109 | offset.x = mj_offsetX;
110 | self.contentOffset = offset;
111 | }
112 |
113 | - (CGFloat)mj_offsetX
114 | {
115 | return self.contentOffset.x;
116 | }
117 |
118 | - (void)setMj_offsetY:(CGFloat)mj_offsetY
119 | {
120 | CGPoint offset = self.contentOffset;
121 | offset.y = mj_offsetY;
122 | self.contentOffset = offset;
123 | }
124 |
125 | - (CGFloat)mj_offsetY
126 | {
127 | return self.contentOffset.y;
128 | }
129 |
130 | - (void)setMj_contentW:(CGFloat)mj_contentW
131 | {
132 | CGSize size = self.contentSize;
133 | size.width = mj_contentW;
134 | self.contentSize = size;
135 | }
136 |
137 | - (CGFloat)mj_contentW
138 | {
139 | return self.contentSize.width;
140 | }
141 |
142 | - (void)setMj_contentH:(CGFloat)mj_contentH
143 | {
144 | CGSize size = self.contentSize;
145 | size.height = mj_contentH;
146 | self.contentSize = size;
147 | }
148 |
149 | - (CGFloat)mj_contentH
150 | {
151 | return self.contentSize.height;
152 | }
153 | @end
154 | #pragma clang diagnostic pop
155 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/UIScrollView+MJRefresh.h:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | // UIScrollView+MJRefresh.h
4 | // MJRefreshExample
5 | //
6 | // Created by MJ Lee on 15/3/4.
7 | // Copyright (c) 2015年 小码哥. All rights reserved.
8 | // 给ScrollView增加下拉刷新、上拉刷新的功能
9 |
10 | #import
11 | #import "MJRefreshConst.h"
12 |
13 | @class MJRefreshHeader, MJRefreshFooter;
14 |
15 | @interface UIScrollView (MJRefresh)
16 | /** 下拉刷新控件 */
17 | @property (strong, nonatomic) MJRefreshHeader *mj_header;
18 | @property (strong, nonatomic) MJRefreshHeader *header MJRefreshDeprecated("使用mj_header");
19 | /** 上拉刷新控件 */
20 | @property (strong, nonatomic) MJRefreshFooter *mj_footer;
21 | @property (strong, nonatomic) MJRefreshFooter *footer MJRefreshDeprecated("使用mj_footer");
22 |
23 | #pragma mark - other
24 | - (NSInteger)mj_totalDataCount;
25 | @property (copy, nonatomic) void (^mj_reloadDataBlock)(NSInteger totalDataCount);
26 | @end
27 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/UIScrollView+MJRefresh.m:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | // UIScrollView+MJRefresh.m
4 | // MJRefreshExample
5 | //
6 | // Created by MJ Lee on 15/3/4.
7 | // Copyright (c) 2015年 小码哥. All rights reserved.
8 | //
9 |
10 | #import "UIScrollView+MJRefresh.h"
11 | #import "MJRefreshHeader.h"
12 | #import "MJRefreshFooter.h"
13 | #import
14 |
15 | @implementation NSObject (MJRefresh)
16 |
17 | + (void)exchangeInstanceMethod1:(SEL)method1 method2:(SEL)method2
18 | {
19 | method_exchangeImplementations(class_getInstanceMethod(self, method1), class_getInstanceMethod(self, method2));
20 | }
21 |
22 | + (void)exchangeClassMethod1:(SEL)method1 method2:(SEL)method2
23 | {
24 | method_exchangeImplementations(class_getClassMethod(self, method1), class_getClassMethod(self, method2));
25 | }
26 |
27 | @end
28 |
29 | @implementation UIScrollView (MJRefresh)
30 |
31 | #pragma mark - header
32 | static const char MJRefreshHeaderKey = '\0';
33 | - (void)setMj_header:(MJRefreshHeader *)mj_header
34 | {
35 | if (mj_header != self.mj_header) {
36 | // 删除旧的,添加新的
37 | [self.mj_header removeFromSuperview];
38 | [self insertSubview:mj_header atIndex:0];
39 |
40 | // 存储新的
41 | objc_setAssociatedObject(self, &MJRefreshHeaderKey,
42 | mj_header, OBJC_ASSOCIATION_RETAIN);
43 | }
44 | }
45 |
46 | - (MJRefreshHeader *)mj_header
47 | {
48 | return objc_getAssociatedObject(self, &MJRefreshHeaderKey);
49 | }
50 |
51 | #pragma mark - footer
52 | static const char MJRefreshFooterKey = '\0';
53 | - (void)setMj_footer:(MJRefreshFooter *)mj_footer
54 | {
55 | if (mj_footer != self.mj_footer) {
56 | // 删除旧的,添加新的
57 | [self.mj_footer removeFromSuperview];
58 | [self insertSubview:mj_footer atIndex:0];
59 |
60 | // 存储新的
61 | objc_setAssociatedObject(self, &MJRefreshFooterKey,
62 | mj_footer, OBJC_ASSOCIATION_RETAIN);
63 | }
64 | }
65 |
66 | - (MJRefreshFooter *)mj_footer
67 | {
68 | return objc_getAssociatedObject(self, &MJRefreshFooterKey);
69 | }
70 |
71 | #pragma mark - 过期
72 | - (void)setFooter:(MJRefreshFooter *)footer
73 | {
74 | self.mj_footer = footer;
75 | }
76 |
77 | - (MJRefreshFooter *)footer
78 | {
79 | return self.mj_footer;
80 | }
81 |
82 | - (void)setHeader:(MJRefreshHeader *)header
83 | {
84 | self.mj_header = header;
85 | }
86 |
87 | - (MJRefreshHeader *)header
88 | {
89 | return self.mj_header;
90 | }
91 |
92 | #pragma mark - other
93 | - (NSInteger)mj_totalDataCount
94 | {
95 | NSInteger totalCount = 0;
96 | if ([self isKindOfClass:[UITableView class]]) {
97 | UITableView *tableView = (UITableView *)self;
98 |
99 | for (NSInteger section = 0; section
11 |
12 | @interface UIView (MJExtension)
13 | @property (assign, nonatomic) CGFloat mj_x;
14 | @property (assign, nonatomic) CGFloat mj_y;
15 | @property (assign, nonatomic) CGFloat mj_w;
16 | @property (assign, nonatomic) CGFloat mj_h;
17 | @property (assign, nonatomic) CGSize mj_size;
18 | @property (assign, nonatomic) CGPoint mj_origin;
19 | @end
20 |
--------------------------------------------------------------------------------
/JXPageListView/Example/MJRefresh/UIView+MJExtension.m:
--------------------------------------------------------------------------------
1 | // 代码地址: https://github.com/CoderMJLee/MJRefresh
2 | // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
3 | // UIView+Extension.m
4 | // MJRefreshExample
5 | //
6 | // Created by MJ Lee on 14-5-28.
7 | // Copyright (c) 2014年 小码哥. All rights reserved.
8 | //
9 |
10 | #import "UIView+MJExtension.h"
11 |
12 | @implementation UIView (MJExtension)
13 | - (void)setMj_x:(CGFloat)mj_x
14 | {
15 | CGRect frame = self.frame;
16 | frame.origin.x = mj_x;
17 | self.frame = frame;
18 | }
19 |
20 | - (CGFloat)mj_x
21 | {
22 | return self.frame.origin.x;
23 | }
24 |
25 | - (void)setMj_y:(CGFloat)mj_y
26 | {
27 | CGRect frame = self.frame;
28 | frame.origin.y = mj_y;
29 | self.frame = frame;
30 | }
31 |
32 | - (CGFloat)mj_y
33 | {
34 | return self.frame.origin.y;
35 | }
36 |
37 | - (void)setMj_w:(CGFloat)mj_w
38 | {
39 | CGRect frame = self.frame;
40 | frame.size.width = mj_w;
41 | self.frame = frame;
42 | }
43 |
44 | - (CGFloat)mj_w
45 | {
46 | return self.frame.size.width;
47 | }
48 |
49 | - (void)setMj_h:(CGFloat)mj_h
50 | {
51 | CGRect frame = self.frame;
52 | frame.size.height = mj_h;
53 | self.frame = frame;
54 | }
55 |
56 | - (CGFloat)mj_h
57 | {
58 | return self.frame.size.height;
59 | }
60 |
61 | - (void)setMj_size:(CGSize)mj_size
62 | {
63 | CGRect frame = self.frame;
64 | frame.size = mj_size;
65 | self.frame = frame;
66 | }
67 |
68 | - (CGSize)mj_size
69 | {
70 | return self.frame.size;
71 | }
72 |
73 | - (void)setMj_origin:(CGPoint)mj_origin
74 | {
75 | CGRect frame = self.frame;
76 | frame.origin = mj_origin;
77 | self.frame = frame;
78 | }
79 |
80 | - (CGPoint)mj_origin
81 | {
82 | return self.frame.origin;
83 | }
84 | @end
85 |
--------------------------------------------------------------------------------
/JXPageListView/Example/NormalHotListView.h:
--------------------------------------------------------------------------------
1 | //
2 | // NormalHotListView.h
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NormalHotListView : UIView
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/Example/NormalHotListView.m:
--------------------------------------------------------------------------------
1 | //
2 | // NormalHotListView.m
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "NormalHotListView.h"
10 |
11 | @interface NormalHotListView()
12 | @property (nonatomic, strong) UITableView *tableView;
13 | @property (nonatomic, strong) NSMutableArray *dataSource;
14 | @end
15 |
16 | @implementation NormalHotListView
17 |
18 | - (instancetype)init
19 | {
20 | self = [super init];
21 | if (self) {
22 | _dataSource = [NSMutableArray array];
23 | for (int i = 0; i < 50; i ++) {
24 | [self.dataSource addObject:[NSString stringWithFormat:@"hot cell:%d", i]];
25 | }
26 |
27 | _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
28 | self.tableView.backgroundColor = [UIColor whiteColor];
29 | self.tableView.tableFooterView = [UIView new];
30 | self.tableView.dataSource = self;
31 | self.tableView.delegate = self;
32 | [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
33 | [self addSubview:self.tableView];
34 | }
35 | return self;
36 | }
37 |
38 | - (void)layoutSubviews {
39 | [super layoutSubviews];
40 |
41 | self.tableView.frame = self.bounds;
42 | }
43 |
44 | #pragma mark - UITableViewDataSource, UITableViewDelegate
45 |
46 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
47 | return self.dataSource.count;
48 | }
49 |
50 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
51 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
52 | cell.textLabel.text = self.dataSource[indexPath.row];
53 | return cell;
54 | }
55 |
56 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
57 | return 50;
58 | }
59 |
60 |
61 | @end
62 |
--------------------------------------------------------------------------------
/JXPageListView/Example/NormalRecommendListView.h:
--------------------------------------------------------------------------------
1 | //
2 | // NormalRecommendListView.h
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NormalRecommendListView : UIView
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/Example/NormalRecommendListView.m:
--------------------------------------------------------------------------------
1 | //
2 | // NormalRecommendListView.m
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "NormalRecommendListView.h"
10 | #import "JXCategoryView.h"
11 | #import "TestListBaseView.h"
12 | #import "UIWindow+JXSafeArea.h"
13 |
14 | @interface NormalRecommendListView()
15 | @property (nonatomic, strong) JXCategoryTitleView *categoryView;
16 | @property (nonatomic, strong) UIScrollView *scrollView;
17 | @end
18 |
19 | @implementation NormalRecommendListView
20 |
21 | - (instancetype)init
22 | {
23 | self = [super init];
24 | if (self) {
25 |
26 | CGFloat naviHeight = [UIApplication.sharedApplication.keyWindow jx_navigationHeight];
27 |
28 | NSUInteger count = 3;
29 | CGFloat categoryViewHeight = 50;
30 | CGFloat width = [UIScreen mainScreen].bounds.size.width;
31 | CGFloat height = [UIScreen mainScreen].bounds.size.height - naviHeight - categoryViewHeight;
32 |
33 | _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, categoryViewHeight, width, height)];
34 | self.scrollView.pagingEnabled = YES;
35 | self.scrollView.contentSize = CGSizeMake(width*count, height);
36 | self.scrollView.bounces = NO;
37 | [self addSubview:self.scrollView];
38 |
39 | if (@available(iOS 11.0, *)) {
40 | self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
41 | }
42 |
43 | TestListBaseView *powerListView = [[TestListBaseView alloc] initWithFrame:CGRectMake(0, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height)];
44 | powerListView.isFirstLoaded = YES;
45 | powerListView.dataSource = @[@"橡胶火箭", @"橡胶火箭炮", @"橡胶机关枪", @"橡胶子弹", @"橡胶攻城炮", @"橡胶象枪", @"橡胶象枪乱打", @"橡胶灰熊铳", @"橡胶雷神象枪", @"橡胶猿王枪", @"橡胶犀·榴弹炮", @"橡胶大蛇炮", @"橡胶火箭", @"橡胶火箭炮", @"橡胶机关枪", @"橡胶子弹", @"橡胶攻城炮", @"橡胶象枪", @"橡胶象枪乱打", @"橡胶灰熊铳", @"橡胶雷神象枪", @"橡胶猿王枪", @"橡胶犀·榴弹炮", @"橡胶大蛇炮"].mutableCopy;
46 | [self.scrollView addSubview:powerListView];
47 |
48 | TestListBaseView *hobbyListView = [[TestListBaseView alloc] initWithFrame:CGRectMake(self.scrollView.bounds.size.width, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height)];
49 | hobbyListView.isFirstLoaded = YES;
50 | hobbyListView.dataSource = @[@"吃烤肉", @"吃鸡腿肉", @"吃牛肉", @"各种肉"].mutableCopy;
51 | [self.scrollView addSubview:hobbyListView];
52 |
53 | TestListBaseView *partnerListView = [[TestListBaseView alloc] initWithFrame:CGRectMake(self.scrollView.bounds.size.width*2, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height)];
54 | partnerListView.isFirstLoaded = YES;
55 | partnerListView.dataSource = @[@"【剑士】罗罗诺亚·索隆", @"【航海士】娜美", @"【狙击手】乌索普", @"【厨师】香吉士", @"【船医】托尼托尼·乔巴", @"【船匠】 弗兰奇", @"【音乐家】布鲁克", @"【考古学家】妮可·罗宾"].mutableCopy;
56 | [self.scrollView addSubview:partnerListView];
57 |
58 | self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, categoryViewHeight)];
59 | self.categoryView.backgroundColor = [UIColor whiteColor];
60 | self.categoryView.titleSelectedColor = [UIColor colorWithRed:105/255.0 green:144/255.0 blue:239/255.0 alpha:1];
61 | self.categoryView.titleColor = [UIColor blackColor];
62 | self.categoryView.titleColorGradientEnabled = YES;
63 | self.categoryView.titleLabelZoomEnabled = YES;
64 | self.categoryView.titles = @[@"能力", @"爱好", @"队友"];
65 |
66 | JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
67 | lineView.indicatorLineViewColor = [UIColor colorWithRed:105/255.0 green:144/255.0 blue:239/255.0 alpha:1];
68 | lineView.indicatorLineWidth = 30;
69 | self.categoryView.indicators = @[lineView];
70 |
71 | self.categoryView.contentScrollView = self.scrollView;
72 | [self addSubview:self.categoryView];
73 |
74 | //添加分割线,这个完全自己配置
75 | UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, categoryViewHeight - 1, width, 1)];
76 | separatorView.backgroundColor = [UIColor lightGrayColor];
77 | [self.categoryView addSubview:separatorView];
78 | }
79 | return self;
80 | }
81 |
82 | @end
83 |
--------------------------------------------------------------------------------
/JXPageListView/Example/NormalViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // NormalViewController.h
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NormalViewController : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/Example/NormalViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // NormalViewController.m
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "NormalViewController.h"
10 | #import "JXCategoryView.h"
11 | #import "NormalHotListView.h"
12 | #import "NormalRecommendListView.h"
13 |
14 | @interface NormalViewController ()
15 | @property (nonatomic, strong) JXCategoryTitleView *categoryView;
16 | @property (nonatomic, strong) UIScrollView *scrollView;
17 | @property (nonatomic, strong) NormalHotListView *hotListView;
18 | @property (nonatomic, strong) NormalRecommendListView *recommendListView;
19 | @end
20 |
21 | @implementation NormalViewController
22 |
23 | - (void)viewDidLoad {
24 | [super viewDidLoad];
25 |
26 | self.title = @"左右分页布局";
27 | self.view.backgroundColor = [UIColor whiteColor];
28 | self.edgesForExtendedLayout = UIRectEdgeNone;
29 | self.automaticallyAdjustsScrollViewInsets = NO;
30 | self.navigationController.navigationBar.translucent = NO;
31 |
32 | self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, 150, 40)];
33 | self.categoryView.backgroundColor = [UIColor whiteColor];
34 | self.categoryView.delegate = self;
35 | self.categoryView.titleSelectedColor = [UIColor colorWithRed:105/255.0 green:144/255.0 blue:239/255.0 alpha:1];
36 | self.categoryView.titleColor = [UIColor blackColor];
37 | self.categoryView.titleColorGradientEnabled = YES;
38 | self.categoryView.titleLabelZoomEnabled = YES;
39 | self.categoryView.titles = @[@"热门", @"推荐"];
40 |
41 | JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
42 | lineView.indicatorLineViewColor = [UIColor colorWithRed:105/255.0 green:144/255.0 blue:239/255.0 alpha:1];
43 | lineView.indicatorLineWidth = 30;
44 | self.categoryView.indicators = @[lineView];
45 |
46 | self.navigationItem.titleView = self.categoryView;
47 |
48 | _scrollView = [[UIScrollView alloc] init];
49 | self.scrollView.pagingEnabled = YES;
50 | self.scrollView.bounces = NO;
51 | if (@available(iOS 11.0, *)) {
52 | self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
53 | }
54 | [self.view addSubview:self.scrollView];
55 |
56 | self.hotListView = [[NormalHotListView alloc] init];
57 | [self.scrollView addSubview:self.hotListView];
58 |
59 | self.recommendListView = [[NormalRecommendListView alloc] init];
60 | [self.scrollView addSubview:self.recommendListView];
61 |
62 | self.categoryView.contentScrollView = self.scrollView;
63 | }
64 |
65 | - (void)viewDidLayoutSubviews {
66 | [super viewDidLayoutSubviews];
67 |
68 | self.scrollView.frame = self.view.bounds;
69 | self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width*2, self.view.bounds.size.height);
70 | self.hotListView.frame = CGRectMake(0, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
71 | self.recommendListView.frame = CGRectMake(self.scrollView.bounds.size.width, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
72 | }
73 |
74 | #pragma mark - JXCategoryViewDelegate
75 |
76 | - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
77 |
78 | }
79 |
80 |
81 | @end
82 |
--------------------------------------------------------------------------------
/JXPageListView/Example/PageViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // PageViewController.h
3 | //
4 | // Created by jiaxin on 2018/9/13.
5 | // Copyright © 2018年 jiaxin. All rights reserved.
6 | //
7 |
8 | #import
9 |
10 | @interface PageViewController : UIViewController
11 | @property (nonatomic, assign) BOOL isNeedHeader;
12 | @property (nonatomic, assign) BOOL listViewScrollStateSaveEnabled;
13 | @property (nonatomic, assign) CGFloat pinCategoryViewVerticalOffset;
14 | @property (nonatomic, assign) BOOL isNeedScrollToBottom;
15 | @end
16 |
--------------------------------------------------------------------------------
/JXPageListView/Example/TestListBaseView.h:
--------------------------------------------------------------------------------
1 | //
2 | // TestListBaseView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/27.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "JXPageListView.h"
11 |
12 | @interface TestListBaseView : UIView < JXPageListViewListDelegate>
13 |
14 | @property (nonatomic, strong) UITableView *tableView;
15 | @property (nonatomic, strong) NSMutableArray *dataSource;
16 | @property (nonatomic, assign) BOOL isNeedHeader;
17 | @property (nonatomic, assign) BOOL isFirstLoaded;
18 | @end
19 |
--------------------------------------------------------------------------------
/JXPageListView/Example/TestListBaseView.m:
--------------------------------------------------------------------------------
1 | //
2 | // TestListBaseView.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/27.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "TestListBaseView.h"
10 | #import "MJRefresh.h"
11 | #import "MBProgressHUD.h"
12 | #import "TestTableView.h"
13 |
14 | @interface TestListBaseView()
15 | @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
16 | @property (nonatomic, strong) NSIndexPath *lastSelectedIndexPath;
17 |
18 | @end
19 |
20 | @implementation TestListBaseView
21 |
22 | - (void)dealloc
23 | {
24 | self.scrollCallback = nil;
25 | }
26 |
27 | - (instancetype)initWithFrame:(CGRect)frame
28 | {
29 | self = [super initWithFrame:frame];
30 | if (self) {
31 | _tableView = [[TestTableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
32 | self.tableView.backgroundColor = [UIColor whiteColor];
33 | self.tableView.tableFooterView = [UIView new];
34 | self.tableView.dataSource = self;
35 | self.tableView.delegate = self;
36 | [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
37 | [self addSubview:self.tableView];
38 | }
39 | return self;
40 | }
41 |
42 | - (void)layoutSubviews {
43 | [super layoutSubviews];
44 |
45 | self.tableView.frame = self.bounds;
46 | }
47 |
48 | - (void)setIsNeedHeader:(BOOL)isNeedHeader {
49 | _isNeedHeader = isNeedHeader;
50 |
51 | __weak typeof(self)weakSelf = self;
52 | if (self.isNeedHeader) {
53 | self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
54 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
55 | [self.tableView reloadData];
56 | [weakSelf.tableView.mj_header endRefreshing];
57 | if (self.dataSource.count >= 10) {
58 | //模拟加载完数据之后添加footer
59 | __strong typeof(weakSelf)strongSelf = weakSelf;
60 | self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
61 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
62 | [strongSelf.dataSource addObject:@"加载更多成功"];
63 | [strongSelf.tableView reloadData];
64 | [strongSelf.tableView.mj_footer endRefreshing];
65 | });
66 | }];
67 | }else {
68 | self.tableView.mj_footer = nil;
69 | }
70 | });
71 | }];
72 | }
73 | }
74 |
75 | - (void)loadMoreDataTest {
76 | [self.dataSource addObject:@"加载更多成功"];
77 | [self.tableView reloadData];
78 | }
79 |
80 | #pragma mark - UITableViewDataSource, UITableViewDelegate
81 |
82 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
83 | if (!self.isFirstLoaded) {
84 | //用来模拟未加载就没有数据,测试代码而已
85 | return 0;
86 | }
87 | return self.dataSource.count;
88 | }
89 |
90 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
92 | cell.textLabel.text = self.dataSource[indexPath.row];
93 | return cell;
94 | }
95 |
96 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
97 | return 50;
98 | }
99 |
100 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
101 |
102 | }
103 |
104 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
105 | !self.scrollCallback?:self.scrollCallback(scrollView);
106 | }
107 |
108 | #pragma mark - JXPagingViewListViewDelegate
109 |
110 | - (UIScrollView *)listScrollView {
111 | return self.tableView;
112 | }
113 |
114 | - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
115 | self.scrollCallback = callback;
116 | }
117 |
118 | - (void)listViewLoadDataIfNeeded {
119 | if (!self.isFirstLoaded) {
120 | self.isFirstLoaded = YES;
121 | if (self.isNeedHeader) {
122 | [self.tableView.mj_header beginRefreshing];
123 | }else {
124 | [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
125 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
126 | [MBProgressHUD hideHUDForView:[UIApplication sharedApplication].keyWindow animated:NO];
127 | [self.tableView reloadData];
128 |
129 | if (self.dataSource.count >= 10) {
130 | //模拟加载完数据之后添加footer
131 | __strong typeof(self)weakSelf = self;
132 | self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
133 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
134 | [weakSelf.dataSource addObject:@"加载更多成功"];
135 | [weakSelf.tableView reloadData];
136 | [weakSelf.tableView.mj_footer endRefreshing];
137 | });
138 | }];
139 | }else {
140 | self.tableView.mj_footer = nil;
141 | }
142 | });
143 | }
144 | }
145 | }
146 |
147 | @end
148 |
--------------------------------------------------------------------------------
/JXPageListView/Example/TestTableView.h:
--------------------------------------------------------------------------------
1 | //
2 | // TestTableView.h
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface TestTableView : UITableView
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/Example/TestTableView.m:
--------------------------------------------------------------------------------
1 | //
2 | // TestTableView.m
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "TestTableView.h"
10 |
11 | @implementation TestTableView
12 |
13 | - (void)setContentInset:(UIEdgeInsets)contentInset {
14 | [super setContentInset:contentInset];
15 |
16 | NSLog(@"contentInset:%f", contentInset.top);
17 | }
18 | /*
19 | // Only override drawRect: if you perform custom drawing.
20 | // An empty implementation adversely affects performance during animation.
21 | - (void)drawRect:(CGRect)rect {
22 | // Drawing code
23 | }
24 | */
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/JXPageListView/Example/UIWindow+JXSafeArea.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIWindow+JXSafeArea.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/9/29.
6 | // Copyright © 2018 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | NS_ASSUME_NONNULL_BEGIN
12 |
13 | @interface UIWindow (JXSafeArea)
14 |
15 | - (UIEdgeInsets)jx_layoutInsets;
16 |
17 | - (CGFloat)jx_navigationHeight;
18 |
19 | @end
20 |
21 | NS_ASSUME_NONNULL_END
22 |
--------------------------------------------------------------------------------
/JXPageListView/Example/UIWindow+JXSafeArea.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIWindow+JXSafeArea.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/9/29.
6 | // Copyright © 2018 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "UIWindow+JXSafeArea.h"
10 |
11 | @implementation UIWindow (JXSafeArea)
12 |
13 | - (UIEdgeInsets)jx_layoutInsets {
14 | if (@available(iOS 11.0, *)) {
15 | UIEdgeInsets safeAreaInsets = self.safeAreaInsets;
16 | if (safeAreaInsets.bottom > 0) {
17 | //参考文章:https://mp.weixin.qq.com/s/Ik2zBox3_w0jwfVuQUJAUw
18 | return safeAreaInsets;
19 | }
20 | return UIEdgeInsetsMake(20, 0, 0, 0);
21 | }
22 | return UIEdgeInsetsMake(20, 0, 0, 0);
23 | }
24 |
25 | - (CGFloat)jx_navigationHeight {
26 | CGFloat statusBarHeight = [self jx_layoutInsets].top;
27 | return statusBarHeight + 44;
28 | }
29 |
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/JXPageListView/Gif/headerLoading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pujiaxin33/JXPageListView/804e26282202bea43a448b6aafc924958922e139/JXPageListView/Gif/headerLoading.gif
--------------------------------------------------------------------------------
/JXPageListView/Gif/hudLoading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pujiaxin33/JXPageListView/804e26282202bea43a448b6aafc924958922e139/JXPageListView/Gif/hudLoading.gif
--------------------------------------------------------------------------------
/JXPageListView/Gif/listScrollStateNoSave.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pujiaxin33/JXPageListView/804e26282202bea43a448b6aafc924958922e139/JXPageListView/Gif/listScrollStateNoSave.gif
--------------------------------------------------------------------------------
/JXPageListView/Gif/listScrollStateSave.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pujiaxin33/JXPageListView/804e26282202bea43a448b6aafc924958922e139/JXPageListView/Gif/listScrollStateSave.gif
--------------------------------------------------------------------------------
/JXPageListView/Gif/scrollInteraction.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pujiaxin33/JXPageListView/804e26282202bea43a448b6aafc924958922e139/JXPageListView/Gif/scrollInteraction.gif
--------------------------------------------------------------------------------
/JXPageListView/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 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 |
35 | UISupportedInterfaceOrientations~ipad
36 |
37 | UIInterfaceOrientationPortrait
38 | UIInterfaceOrientationPortraitUpsideDown
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Base/JXCategoryBaseCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryBaseCell.h
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/15.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "JXCategoryBaseCellModel.h"
11 |
12 | @interface JXCategoryBaseCell : UICollectionViewCell
13 |
14 | @property (nonatomic, strong) JXCategoryBaseCellModel *cellModel;
15 |
16 | - (void)initializeViews NS_REQUIRES_SUPER;
17 |
18 | - (void)reloadData:(JXCategoryBaseCellModel *)cellModel NS_REQUIRES_SUPER;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Base/JXCategoryBaseCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryBaseCell.m
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/15.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryBaseCell.h"
10 |
11 | @interface JXCategoryBaseCell ()
12 | @end
13 |
14 | @implementation JXCategoryBaseCell
15 |
16 | - (instancetype)initWithFrame:(CGRect)frame
17 | {
18 | self = [super initWithFrame:frame];
19 | if (self) {
20 | [self initializeViews];
21 | }
22 | return self;
23 | }
24 |
25 | - (void)initializeViews
26 | {
27 |
28 | }
29 |
30 | - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
31 | self.cellModel = cellModel;
32 |
33 | }
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Base/JXCategoryBaseCellModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryBaseCellModel.h
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/15.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface JXCategoryBaseCellModel : NSObject
13 |
14 | @property (nonatomic, assign) NSUInteger index;
15 |
16 | @property (nonatomic, assign) BOOL selected;
17 |
18 | @property (nonatomic, assign) CGFloat cellWidth;
19 |
20 | @property (nonatomic, assign) CGFloat cellSpacing;
21 |
22 | @property (nonatomic, assign) BOOL cellWidthZoomEnabled;
23 |
24 | @property (nonatomic, assign) CGFloat cellWidthZoomScale;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Base/JXCategoryBaseCellModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryBaseCellModel.m
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/15.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryBaseCellModel.h"
10 |
11 | @implementation JXCategoryBaseCellModel
12 |
13 | - (CGFloat)cellWidth {
14 | if (_cellWidthZoomEnabled) {
15 | return _cellWidth * _cellWidthZoomScale;
16 | }
17 | return _cellWidth;
18 | }
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Common/JXCategoryCollectionView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryCollectionView.h
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/21.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "JXCategoryIndicatorProtocol.h"
11 |
12 | @interface JXCategoryCollectionView : UICollectionView
13 |
14 | @property (nonatomic, strong) NSArray *> *indicators;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Common/JXCategoryCollectionView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryCollectionView.m
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/21.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryCollectionView.h"
10 |
11 | @implementation JXCategoryCollectionView
12 |
13 | - (void)layoutSubviews
14 | {
15 | [super layoutSubviews];
16 |
17 | for (UIView *view in self.indicators) {
18 | [self sendSubviewToBack:view];
19 | }
20 | }
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Common/JXCategoryFactory.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryFactory.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface JXCategoryFactory : NSObject
13 |
14 | + (CGFloat)interpolationFrom:(CGFloat)from to:(CGFloat)to percent:(CGFloat)percent;
15 |
16 | + (UIColor *)interpolationColorFrom:(UIColor *)fromColor to:(UIColor *)toColor percent:(CGFloat)percent;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Common/JXCategoryFactory.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryFactory.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryFactory.h"
10 | #import "UIColor+JXAdd.h"
11 |
12 | @implementation JXCategoryFactory
13 |
14 | + (CGFloat)interpolationFrom:(CGFloat)from to:(CGFloat)to percent:(CGFloat)percent
15 | {
16 | percent = MAX(0, MIN(1, percent));
17 | return from + (to - from)*percent;
18 | }
19 |
20 | + (UIColor *)interpolationColorFrom:(UIColor *)fromColor to:(UIColor *)toColor percent:(CGFloat)percent
21 | {
22 | CGFloat red = [self interpolationFrom:fromColor.jx_red to:toColor.jx_red percent:percent];
23 | CGFloat green = [self interpolationFrom:fromColor.jx_green to:toColor.jx_green percent:percent];
24 | CGFloat blue = [self interpolationFrom:fromColor.jx_blue to:toColor.jx_blue percent:percent];
25 | CGFloat alpha = [self interpolationFrom:fromColor.jx_alpha to:toColor.jx_alpha percent:percent];
26 | return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
27 | }
28 |
29 | @end
30 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Common/JXCategoryIndicatorProtocol.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryComponentProtocol.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import "JXCategoryViewDefines.h"
12 |
13 | @protocol JXCategoryIndicatorProtocol
14 |
15 | - (void)jx_refreshState:(CGRect)selectedCellFrame;
16 |
17 |
18 | /**
19 | contentScrollView在进行手势滑动时,处理指示器跟随手势变化UI逻辑;
20 |
21 | @param leftCellFrame 正在过渡中的两个cell,相对位置在左边的cell的frame
22 | @param rightCellFrame 正在过渡中的两个cell,相对位置在右边的cell的frame
23 | @param selectedPosition 当前处于选中状态的cell的位置
24 | @param percent 过渡百分比
25 | */
26 | - (void)jx_contentScrollViewDidScrollWithLeftCellFrame:(CGRect)leftCellFrame rightCellFrame:(CGRect)rightCellFrame selectedPosition:(JXCategoryCellClickedPosition)selectedPosition percent:(CGFloat)percent;
27 |
28 | /**
29 | 点击选中了某一个cell
30 |
31 | @param cellFrame cell的frame
32 | @param clickedRelativePosition 相对于已选中cell,当前点击的cell的相对位置。比如 A、B、C 当前处于选中状态的是B。点击了A是JXCategoryCellClickedPosition_Left;点击了C是JXCategoryCellClickedPosition_Right;
33 | */
34 | - (void)jx_selectedCell:(CGRect)cellFrame clickedRelativePosition:(JXCategoryCellClickedPosition)clickedRelativePosition;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Common/JXCategoryListVCContainerView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryListScrollView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/9/12.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | /**
13 | 使用方法参照demo工程的LoadDataViewController文件
14 | */
15 | @interface JXCategoryListVCContainerView : UIView
16 |
17 | @property (nonatomic, weak) UIViewController *parentViewController;
18 | @property (nonatomic, strong, readonly) UIScrollView *scrollView;
19 | @property (nonatomic, strong) NSArray *listVCArray;
20 | //这个defaultSelectedIndex仅仅用于触发对应index的数据加载,如果要让categoryView和listView都处于对应的index。还应该添加后面这段代码:self.categoryView.defaultSelectedIndex = n
21 | @property (nonatomic, assign) NSInteger defaultSelectedIndex;
22 |
23 | - (void)reloadData;
24 |
25 | - (void)scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio;
26 |
27 | - (void)didClickSelectedItemAtIndex:(NSInteger)index;
28 |
29 | - (void)didScrollSelectedItemAtIndex:(NSInteger)index;
30 |
31 | - (void)parentVCWillAppear:(BOOL)animated;
32 |
33 | - (void)parentVCDidAppear:(BOOL)animated;
34 |
35 | - (void)parentVCWillDisappear:(BOOL)animated;
36 |
37 | - (void)parentVCDidDisappear:(BOOL)animated;
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Common/JXCategoryListVCContainerView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryListContainerView.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/9/12.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryListVCContainerView.h"
10 |
11 | @interface JXCategoryListVCContainerView ()
12 | @property (nonatomic, strong) UIScrollView *scrollView;
13 | @property (nonatomic, assign) NSInteger currentIndex;
14 | @property (nonatomic, assign) NSInteger targetIndex;
15 | @end
16 |
17 | @implementation JXCategoryListVCContainerView
18 |
19 | - (instancetype)initWithFrame:(CGRect)frame {
20 | self = [super initWithFrame:frame];
21 | if (self) {
22 | [self initializeViews];
23 | }
24 | return self;
25 | }
26 |
27 | - (instancetype)initWithCoder:(NSCoder *)coder
28 | {
29 | self = [super initWithCoder:coder];
30 | if (self) {
31 | [self initializeViews];
32 | }
33 | return self;
34 | }
35 |
36 | - (void)initializeViews {
37 | _scrollView = [[UIScrollView alloc] init];
38 | self.scrollView.pagingEnabled = YES;
39 | self.scrollView.showsHorizontalScrollIndicator = NO;
40 | [self addSubview:self.scrollView];
41 | }
42 |
43 | - (void)reloadData {
44 | [self listVCWillAppear:self.defaultSelectedIndex];
45 | [self listVCDidAppear:self.defaultSelectedIndex];
46 | }
47 |
48 | - (void)layoutSubviews {
49 | [super layoutSubviews];
50 |
51 | self.scrollView.frame = self.bounds;
52 | //根据新的数据源重新添加listView
53 | for (int i = 0; i < self.listVCArray.count; i ++) {
54 | UIViewController *listVC = self.listVCArray[i];
55 | [listVC willMoveToParentViewController:self.parentViewController];
56 | [self.parentViewController addChildViewController:self.parentViewController];
57 | [listVC didMoveToParentViewController:self.parentViewController];
58 | listVC.view.frame = CGRectMake(i*self.scrollView.bounds.size.width, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
59 | [self.scrollView addSubview:listVC.view];
60 | }
61 |
62 | self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.size.width*self.listVCArray.count, self.scrollView.bounds.size.height);
63 | }
64 |
65 | - (void)setListVCArray:(NSArray *)listVCArray {
66 | for (UIViewController *vc in self.listVCArray) {
67 | [vc.view removeFromSuperview];
68 | }
69 | _listVCArray = listVCArray;
70 |
71 | [self setNeedsLayout];
72 | }
73 |
74 | - (void)setDefaultSelectedIndex:(NSInteger)defaultSelectedIndex {
75 | _defaultSelectedIndex = defaultSelectedIndex;
76 |
77 | self.currentIndex = defaultSelectedIndex;
78 | }
79 |
80 | - (void)parentVCWillAppear:(BOOL)animated {
81 | [self listVCWillAppear:self.currentIndex];
82 | }
83 |
84 | - (void)parentVCDidAppear:(BOOL)animated {
85 | [self listVCDidAppear:self.currentIndex];
86 | }
87 |
88 | - (void)parentVCWillDisappear:(BOOL)animated {
89 | [self listVCWillDisappear:self.currentIndex];
90 | }
91 |
92 | - (void)parentVCDidDisappear:(BOOL)animated {
93 | [self listVCDidDisappear:self.currentIndex];
94 | }
95 |
96 | - (void)scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
97 | NSInteger targetIndex = 0;
98 | if (ratio > 0.5) {
99 | targetIndex = leftIndex;
100 | }else {
101 | targetIndex = rightIndex;
102 | }
103 | if (self.targetIndex != targetIndex) {
104 | [self listVCWillAppear:targetIndex];
105 | [self listVCDidAppear:targetIndex];
106 |
107 | [self listVCWillDisappear:self.currentIndex];
108 | [self listVCDidDisappear:self.currentIndex];
109 | }
110 | }
111 |
112 | - (void)didScrollSelectedItemAtIndex:(NSInteger)index {
113 |
114 | }
115 |
116 | - (void)didClickSelectedItemAtIndex:(NSInteger)index {
117 | [self listVCWillDisappear:self.currentIndex];
118 | [self listVCDidDisappear:self.currentIndex];
119 |
120 | [self listVCWillAppear:index];
121 | [self listVCDidAppear:index];
122 | }
123 |
124 | #pragma mark - Private
125 |
126 | - (void)listVCWillAppear:(NSInteger)index {
127 | self.targetIndex = index;
128 |
129 | UIViewController *vc = self.listVCArray[index];
130 | [vc beginAppearanceTransition:YES animated:YES];
131 | }
132 |
133 | - (void)listVCDidAppear:(NSInteger)index {
134 | self.currentIndex = index;
135 | UIViewController *vc = self.listVCArray[index];
136 | [vc endAppearanceTransition];
137 | }
138 |
139 | - (void)listVCWillDisappear:(NSInteger)index {
140 | UIViewController *vc = self.listVCArray[index];
141 | [vc beginAppearanceTransition:NO animated:YES];
142 | }
143 |
144 | - (void)listVCDidDisappear:(NSInteger)index {
145 | UIViewController *vc = self.listVCArray[index];
146 | [vc endAppearanceTransition];
147 | }
148 |
149 |
150 | @end
151 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Common/JXCategoryViewDefines.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryViewDefines.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | static const CGFloat JXCategoryViewAutomaticDimension = -1;
13 |
14 | typedef NS_ENUM(NSUInteger, JXCategoryComponentPosition) {
15 | JXCategoryComponentPosition_Bottom,
16 | JXCategoryComponentPosition_Top,
17 | };
18 |
19 | typedef NS_ENUM(NSUInteger, JXCategoryCellClickedPosition) {
20 | JXCategoryCellClickedPosition_Left,
21 | JXCategoryCellClickedPosition_Right,
22 | };
23 |
24 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Common/UIColor+JXAdd.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIColor+JXAdd.h
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/21.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIColor (JXAdd)
12 |
13 | @property (nonatomic, assign, readonly) CGFloat jx_red;
14 | @property (nonatomic, assign, readonly) CGFloat jx_green;
15 | @property (nonatomic, assign, readonly) CGFloat jx_blue;
16 | @property (nonatomic, assign, readonly) CGFloat jx_alpha;
17 |
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Common/UIColor+JXAdd.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIColor+JXAdd.m
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/21.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "UIColor+JXAdd.h"
10 |
11 | @implementation UIColor (JXAdd)
12 |
13 | - (CGFloat)jx_red {
14 | CGFloat r = 0, g, b, a;
15 | [self getRed:&r green:&g blue:&b alpha:&a];
16 | return r;
17 | }
18 |
19 | - (CGFloat)jx_green {
20 | CGFloat r, g = 0, b, a;
21 | [self getRed:&r green:&g blue:&b alpha:&a];
22 | return g;
23 | }
24 |
25 | - (CGFloat)jx_blue {
26 | CGFloat r, g, b = 0, a;
27 | [self getRed:&r green:&g blue:&b alpha:&a];
28 | return b;
29 | }
30 |
31 | - (CGFloat)jx_alpha {
32 | return CGColorGetAlpha(self.CGColor);
33 | }
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Dot/JXCategoryDotCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryDotCell.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleCell.h"
10 |
11 | @interface JXCategoryDotCell : JXCategoryTitleCell
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Dot/JXCategoryDotCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryDotCell.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryDotCell.h"
10 | #import "JXCategoryDotCellModel.h"
11 |
12 | @interface JXCategoryDotCell ()
13 | @property (nonatomic, strong) CALayer *dotLayer;
14 | @end
15 |
16 | @implementation JXCategoryDotCell
17 |
18 | - (void)initializeViews {
19 | [super initializeViews];
20 |
21 | _dotLayer = [CALayer layer];
22 | [self.contentView.layer addSublayer:self.dotLayer];
23 | }
24 |
25 | - (void)layoutSubviews {
26 | [super layoutSubviews];
27 |
28 | [CATransaction begin];
29 | [CATransaction setDisableActions:YES];
30 |
31 | JXCategoryDotCellModel *myCellModel = (JXCategoryDotCellModel *)self.cellModel;
32 | self.dotLayer.bounds = CGRectMake(0, 0, myCellModel.dotSize.width, myCellModel.dotSize.height);
33 | switch (myCellModel.relativePosition) {
34 | case JXCategoryDotRelativePosition_TopLeft:
35 | {
36 | self.dotLayer.position = CGPointMake(CGRectGetMinX(self.titleLabel.frame), CGRectGetMinY(self.titleLabel.frame));
37 | }
38 | break;
39 | case JXCategoryDotRelativePosition_TopRight:
40 | {
41 | self.dotLayer.position = CGPointMake(CGRectGetMaxX(self.titleLabel.frame), CGRectGetMinY(self.titleLabel.frame));
42 | }
43 | break;
44 | case JXCategoryDotRelativePosition_BottomLeft:
45 | {
46 | self.dotLayer.position = CGPointMake(CGRectGetMinX(self.titleLabel.frame), CGRectGetMaxY(self.titleLabel.frame));
47 | }
48 | break;
49 | case JXCategoryDotRelativePosition_BottomRight:
50 | {
51 | self.dotLayer.position = CGPointMake(CGRectGetMaxX(self.titleLabel.frame), CGRectGetMaxY(self.titleLabel.frame));
52 | }
53 | break;
54 |
55 | default:
56 | break;
57 | }
58 | self.dotLayer.position = CGPointMake(CGRectGetMaxX(self.titleLabel.frame), CGRectGetMinY(self.titleLabel.frame));
59 |
60 | [CATransaction commit];
61 | }
62 |
63 | - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
64 | [super reloadData:cellModel];
65 |
66 | JXCategoryDotCellModel *myCellModel = (JXCategoryDotCellModel *)cellModel;
67 | [CATransaction begin];
68 | [CATransaction setDisableActions:YES];
69 | self.dotLayer.hidden = !myCellModel.dotHidden;
70 | self.dotLayer.backgroundColor = myCellModel.dotColor.CGColor;
71 | self.dotLayer.cornerRadius = myCellModel.dotCornerRadius;
72 | [CATransaction commit];
73 |
74 | [self setNeedsLayout];
75 | [self layoutIfNeeded];
76 | }
77 |
78 | @end
79 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Dot/JXCategoryDotCellModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryDotCellModel.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleCellModel.h"
10 |
11 | typedef NS_ENUM(NSUInteger, JXCategoryDotRelativePosition) {
12 | JXCategoryDotRelativePosition_TopLeft = 0,
13 | JXCategoryDotRelativePosition_TopRight,
14 | JXCategoryDotRelativePosition_BottomLeft,
15 | JXCategoryDotRelativePosition_BottomRight,
16 | };
17 |
18 | @interface JXCategoryDotCellModel : JXCategoryTitleCellModel
19 |
20 | @property (nonatomic, assign) BOOL dotHidden;
21 |
22 | @property (nonatomic, assign) JXCategoryDotRelativePosition relativePosition;
23 |
24 | @property (nonatomic, assign) CGSize dotSize;
25 |
26 | @property (nonatomic, assign) CGFloat dotCornerRadius;
27 |
28 | @property (nonatomic, strong) UIColor *dotColor;
29 |
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Dot/JXCategoryDotCellModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryDotCellModel.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryDotCellModel.h"
10 |
11 | @implementation JXCategoryDotCellModel
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Dot/JXCategoryDotView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryDotView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleView.h"
10 | #import "JXCategoryDotCell.h"
11 | #import "JXCategoryDotCellModel.h"
12 |
13 | @interface JXCategoryDotView : JXCategoryTitleView
14 |
15 | @property (nonatomic, assign) JXCategoryDotRelativePosition relativePosition; //相对于titleLabel的位置,默认:JXCategoryDotRelativePosition_TopRight
16 |
17 | @property (nonatomic, strong) NSArray *dotStates; //@(布尔值),控制红点是否显示
18 |
19 | @property (nonatomic, assign) CGSize dotSize; //默认:CGSizeMake(10, 10)
20 |
21 | @property (nonatomic, assign) CGFloat dotCornerRadius; //默认:JXCategoryViewAutomaticDimension(self.dotSize.height/2)
22 |
23 | @property (nonatomic, strong) UIColor *dotColor; //默认:[UIColor redColor]
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Dot/JXCategoryDotView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryDotView.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryDotView.h"
10 |
11 | @implementation JXCategoryDotView
12 |
13 | - (void)initializeData {
14 | [super initializeData];
15 |
16 | _relativePosition = JXCategoryDotRelativePosition_TopRight;
17 | _dotSize = CGSizeMake(10, 10);
18 | _dotCornerRadius = JXCategoryViewAutomaticDimension;
19 | _dotColor = [UIColor redColor];
20 | }
21 |
22 | - (Class)preferredCellClass {
23 | return [JXCategoryDotCell class];
24 | }
25 |
26 | - (void)refreshDataSource {
27 | NSMutableArray *tempArray = [NSMutableArray array];
28 | for (int i = 0; i < self.titles.count; i++) {
29 | JXCategoryDotCellModel *cellModel = [[JXCategoryDotCellModel alloc] init];
30 | [tempArray addObject:cellModel];
31 | }
32 | self.dataSource = tempArray;
33 | }
34 |
35 | - (void)refreshCellModel:(JXCategoryBaseCellModel *)cellModel index:(NSInteger)index {
36 | [super refreshCellModel:cellModel index:index];
37 |
38 | JXCategoryDotCellModel *myCellModel = (JXCategoryDotCellModel *)cellModel;
39 | myCellModel.dotHidden = [self.dotStates[index] boolValue];
40 | myCellModel.relativePosition = self.relativePosition;
41 | myCellModel.dotSize = self.dotSize;
42 | myCellModel.dotColor = self.dotColor;
43 | if (self.dotCornerRadius == JXCategoryViewAutomaticDimension) {
44 | myCellModel.dotCornerRadius = self.dotSize.height/2;
45 | }else {
46 | myCellModel.dotCornerRadius = self.dotCornerRadius;
47 | }
48 | }
49 |
50 | @end
51 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Image/JXCategoryImageCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryImageCell.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorCell.h"
10 |
11 | @interface JXCategoryImageCell : JXCategoryIndicatorCell
12 |
13 | @property (nonatomic, strong) UIImageView *imageView;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Image/JXCategoryImageCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryImageCell.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryImageCell.h"
10 | #import "JXCategoryImageCellModel.h"
11 |
12 | @implementation JXCategoryImageCell
13 |
14 | - (void)initializeViews {
15 | [super initializeViews];
16 |
17 | _imageView = [[UIImageView alloc] init];
18 | _imageView.contentMode = UIViewContentModeScaleAspectFit;
19 | [self.contentView addSubview:_imageView];
20 | }
21 |
22 | - (void)layoutSubviews {
23 | [super layoutSubviews];
24 |
25 | JXCategoryImageCellModel *myCellModel = (JXCategoryImageCellModel *)self.cellModel;
26 | self.imageView.bounds = CGRectMake(0, 0, myCellModel.imageSize.width, myCellModel.imageSize.height);
27 | self.imageView.center = self.contentView.center;
28 | }
29 |
30 | - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
31 | [super reloadData:cellModel];
32 |
33 | JXCategoryImageCellModel *myCellModel = (JXCategoryImageCellModel *)cellModel;
34 | if (myCellModel.imageName != nil) {
35 | self.imageView.image = [UIImage imageNamed:myCellModel.imageName];
36 | }else if (myCellModel.imageURL != nil) {
37 | if (myCellModel.loadImageCallback != nil) {
38 | myCellModel.loadImageCallback(self.imageView, myCellModel.imageURL);
39 | }
40 | }
41 | if (myCellModel.selected) {
42 | if (myCellModel.selectedImageName != nil) {
43 | self.imageView.image = [UIImage imageNamed:myCellModel.selectedImageName];
44 | }else if (myCellModel.selectedImageURL != nil) {
45 | if (myCellModel.loadImageCallback != nil) {
46 | myCellModel.loadImageCallback(self.imageView, myCellModel.selectedImageURL);
47 | }
48 | }
49 | }
50 |
51 | if (myCellModel.imageZoomEnabled) {
52 | self.imageView.transform = CGAffineTransformMakeScale(myCellModel.imageZoomScale, myCellModel.imageZoomScale);
53 | }else {
54 | self.imageView.transform = CGAffineTransformIdentity;
55 | }
56 | }
57 |
58 | @end
59 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Image/JXCategoryImageCellModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryImageCellModel.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorCellModel.h"
10 |
11 | @interface JXCategoryImageCellModel : JXCategoryIndicatorCellModel
12 |
13 | @property (nonatomic, copy) void(^loadImageCallback)(UIImageView *imageView, NSURL *imageURL);
14 |
15 | @property (nonatomic, copy) NSString *imageName; //加载bundle内的图片
16 |
17 | @property (nonatomic, strong) NSURL *imageURL; //图片URL
18 |
19 | @property (nonatomic, copy) NSString *selectedImageName;
20 |
21 | @property (nonatomic, strong) NSURL *selectedImageURL;
22 |
23 | @property (nonatomic, assign) CGSize imageSize;
24 |
25 | @property (nonatomic, assign) BOOL imageZoomEnabled;
26 |
27 | @property (nonatomic, assign) CGFloat imageZoomScale;
28 |
29 | @end
30 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Image/JXCategoryImageCellModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryImageCellModel.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryImageCellModel.h"
10 |
11 | @implementation JXCategoryImageCellModel
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Image/JXCategoryImageView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryImageView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorView.h"
10 | #import "JXCategoryImageCell.h"
11 | #import "JXCategoryImageCellModel.h"
12 |
13 | @interface JXCategoryImageView : JXCategoryIndicatorView
14 |
15 | @property (nonatomic, strong) NSArray *imageNames;
16 |
17 | @property (nonatomic, strong) NSArray *imageURLs;
18 |
19 | @property (nonatomic, strong) NSArray *selectedImageNames;
20 |
21 | @property (nonatomic, strong) NSArray *selectedImageURLs;
22 |
23 | @property (nonatomic, copy) void(^loadImageCallback)(UIImageView *imageView, NSURL *imageURL); //使用imageURL从远端下载图片进行加载,建议使用SDWebImage等第三方库进行下载。
24 |
25 | @property (nonatomic, assign) CGSize imageSize; //默认CGSizeMake(20, 20)
26 |
27 | @property (nonatomic, assign) BOOL imageZoomEnabled; //默认为NO
28 |
29 | @property (nonatomic, assign) CGFloat imageZoomScale; //默认1.2,imageZoomEnabled为YES才生效
30 |
31 | @end
32 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Image/JXCategoryImageView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryImageView.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/20.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryImageView.h"
10 | #import "JXCategoryFactory.h"
11 |
12 | @implementation JXCategoryImageView
13 |
14 | - (void)dealloc
15 | {
16 | self.loadImageCallback = nil;
17 | }
18 |
19 | - (void)initializeData {
20 | [super initializeData];
21 |
22 | _imageSize = CGSizeMake(20, 20);
23 | _imageZoomEnabled = NO;
24 | _imageZoomScale = 1.2;
25 | }
26 |
27 | - (Class)preferredCellClass {
28 | return [JXCategoryImageCell class];
29 | }
30 |
31 | - (void)refreshDataSource {
32 | NSMutableArray *tempArray = [NSMutableArray array];
33 | NSUInteger count = (self.imageNames.count > 0) ? self.imageNames.count : (self.imageURLs.count > 0 ? self.imageURLs.count : 0);
34 | for (int i = 0; i < count; i++) {
35 | JXCategoryImageCellModel *cellModel = [[JXCategoryImageCellModel alloc] init];
36 | [tempArray addObject:cellModel];
37 | }
38 | self.dataSource = tempArray;
39 | }
40 |
41 | - (void)refreshSelectedCellModel:(JXCategoryBaseCellModel *)selectedCellModel unselectedCellModel:(JXCategoryBaseCellModel *)unselectedCellModel {
42 | [super refreshSelectedCellModel:selectedCellModel unselectedCellModel:unselectedCellModel];
43 |
44 | JXCategoryImageCellModel *myUnselectedCellModel = (JXCategoryImageCellModel *)unselectedCellModel;
45 | myUnselectedCellModel.imageZoomScale = 1.0;
46 |
47 | JXCategoryImageCellModel *myselectedCellModel = (JXCategoryImageCellModel *)selectedCellModel;
48 | myselectedCellModel.imageZoomScale = self.imageZoomScale;
49 | }
50 |
51 | - (void)refreshCellModel:(JXCategoryBaseCellModel *)cellModel index:(NSInteger)index {
52 | [super refreshCellModel:cellModel index:index];
53 |
54 | JXCategoryImageCellModel *myCellModel = (JXCategoryImageCellModel *)cellModel;
55 | myCellModel.loadImageCallback = self.loadImageCallback;
56 | myCellModel.imageSize = self.imageSize;
57 | if (self.imageNames != nil) {
58 | myCellModel.imageName = self.imageNames[index];
59 | }else if (self.imageURLs != nil) {
60 | myCellModel.imageURL = self.imageURLs[index];
61 | }
62 | if (self.selectedImageNames != nil) {
63 | myCellModel.selectedImageName = self.selectedImageNames[index];
64 | }else if (self.selectedImageURLs != nil) {
65 | myCellModel.selectedImageURL = self.selectedImageURLs[index];
66 | }
67 | myCellModel.imageZoomEnabled = self.imageZoomEnabled;
68 | myCellModel.imageZoomScale = 1.0;
69 | if (index == self.selectedIndex) {
70 | myCellModel.imageZoomScale = self.imageZoomScale;
71 | }
72 | }
73 |
74 | - (void)refreshLeftCellModel:(JXCategoryBaseCellModel *)leftCellModel rightCellModel:(JXCategoryBaseCellModel *)rightCellModel ratio:(CGFloat)ratio {
75 | [super refreshLeftCellModel:leftCellModel rightCellModel:rightCellModel ratio:ratio];
76 |
77 | JXCategoryImageCellModel *leftModel = (JXCategoryImageCellModel *)leftCellModel;
78 | JXCategoryImageCellModel *rightModel = (JXCategoryImageCellModel *)rightCellModel;
79 |
80 | if (self.imageZoomEnabled) {
81 | leftModel.imageZoomScale = [JXCategoryFactory interpolationFrom:self.imageZoomScale to:1.0 percent:ratio];
82 | rightModel.imageZoomScale = [JXCategoryFactory interpolationFrom:1.0 to:self.imageZoomScale percent:ratio];
83 | }
84 | }
85 |
86 | - (CGFloat)preferredCellWidthAtIndex:(NSInteger)index {
87 | return self.imageSize.width;
88 | }
89 |
90 | @end
91 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/IndicatorViews/JXCategoryIndicatorBackgroundView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryIndicatorBackgroundView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorComponentView.h"
10 |
11 | @interface JXCategoryIndicatorBackgroundView : JXCategoryIndicatorComponentView
12 |
13 | @property (nonatomic, assign) CGFloat backgroundViewWidth; //默认JXCategoryViewAutomaticDimension(与cellWidth相等)
14 |
15 | @property (nonatomic, assign) CGFloat backgroundViewWidthIncrement; //宽度增量补偿,因为backgroundEllipseLayer一般会比实际内容大一些。默认10
16 |
17 | @property (nonatomic, assign) CGFloat backgroundViewHeight; //默认JXCategoryViewAutomaticDimension(与cell高度相等)
18 |
19 | @property (nonatomic, assign) CGFloat backgroundViewCornerRadius; //默认JXCategoryViewAutomaticDimension(即backgroundViewHeight/2)
20 |
21 | @property (nonatomic, strong) UIColor *backgroundViewColor; //默认为[UIColor redColor]
22 |
23 | @end
24 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/IndicatorViews/JXCategoryIndicatorBackgroundView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryIndicatorBackgroundView.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorBackgroundView.h"
10 | #import "JXCategoryFactory.h"
11 |
12 | @implementation JXCategoryIndicatorBackgroundView
13 |
14 | - (instancetype)initWithFrame:(CGRect)frame
15 | {
16 | self = [super initWithFrame:frame];
17 | if (self) {
18 | _backgroundViewWidth = JXCategoryViewAutomaticDimension;
19 | _backgroundViewHeight = JXCategoryViewAutomaticDimension;
20 | _backgroundViewCornerRadius = JXCategoryViewAutomaticDimension;
21 | _backgroundViewColor = [UIColor lightGrayColor];
22 | _backgroundViewWidthIncrement = 10;
23 | }
24 | return self;
25 | }
26 |
27 | #pragma mark - JXCategoryComponentProtocol
28 |
29 | - (void)jx_refreshState:(CGRect)selectedCellFrame {
30 | self.layer.cornerRadius = [self getBackgroundViewCornerRadius:selectedCellFrame];
31 | self.backgroundColor = self.backgroundViewColor;
32 |
33 | CGFloat width = [self getBackgroundViewWidth:selectedCellFrame];
34 | CGFloat height = [self getBackgroundViewHeight:selectedCellFrame];
35 | CGFloat x = selectedCellFrame.origin.x + (selectedCellFrame.size.width - width)/2;
36 | CGFloat y = (selectedCellFrame.size.height - height)/2;
37 | self.frame = CGRectMake(x, y, width, height);
38 | }
39 |
40 | - (void)jx_contentScrollViewDidScrollWithLeftCellFrame:(CGRect)leftCellFrame rightCellFrame:(CGRect)rightCellFrame selectedPosition:(JXCategoryCellClickedPosition)selectedPosition percent:(CGFloat)percent {
41 |
42 | CGFloat targetX = leftCellFrame.origin.x;
43 | CGFloat targetWidth = [self getBackgroundViewWidth:leftCellFrame];
44 |
45 | if (percent == 0) {
46 | targetX = leftCellFrame.origin.x + (leftCellFrame.size.width - targetWidth)/2.0;
47 | }else {
48 | CGFloat leftWidth = targetWidth;
49 | CGFloat rightWidth = [self getBackgroundViewWidth:rightCellFrame];
50 |
51 | CGFloat leftX = leftCellFrame.origin.x + (leftCellFrame.size.width - leftWidth)/2;
52 | CGFloat rightX = rightCellFrame.origin.x + (rightCellFrame.size.width - rightWidth)/2;
53 |
54 | targetX = [JXCategoryFactory interpolationFrom:leftX to:rightX percent:percent];
55 |
56 | if (self.backgroundViewWidth == JXCategoryViewAutomaticDimension) {
57 | targetWidth = [JXCategoryFactory interpolationFrom:leftWidth to:rightWidth percent:percent];
58 | }
59 | }
60 |
61 | //允许变动frame的情况:1、允许滚动;2、不允许滚动,但是已经通过手势滚动切换一页内容了;
62 | if (self.scrollEnabled == YES || (self.scrollEnabled == NO && percent == 0)) {
63 | CGFloat height = [self getBackgroundViewHeight:leftCellFrame];
64 | CGFloat y = (leftCellFrame.size.height - height)/2;
65 | self.frame = CGRectMake(targetX, y, targetWidth, height);
66 | }
67 | }
68 |
69 | - (void)jx_selectedCell:(CGRect)cellFrame clickedRelativePosition:(JXCategoryCellClickedPosition)clickedRelativePosition {
70 | CGFloat width = [self getBackgroundViewWidth:cellFrame];
71 | CGFloat height = [self getBackgroundViewHeight:cellFrame];
72 | CGFloat x = cellFrame.origin.x + (cellFrame.size.width - width)/2;
73 | CGFloat y = (cellFrame.size.height - height)/2;
74 | CGRect toFrame = CGRectMake(x, y, width, height);
75 |
76 | if (self.scrollEnabled) {
77 | [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
78 | self.frame = toFrame;
79 | } completion:^(BOOL finished) {
80 | }];
81 | }else {
82 | self.frame = toFrame;
83 | }
84 | }
85 |
86 | #pragma mark - Private
87 |
88 | - (CGFloat)getBackgroundViewWidth:(CGRect)cellFrame
89 | {
90 | if (self.backgroundViewWidth == JXCategoryViewAutomaticDimension) {
91 | return cellFrame.size.width + self.backgroundViewWidthIncrement;
92 | }
93 | return self.backgroundViewWidth + self.backgroundViewWidthIncrement;
94 | }
95 |
96 | - (CGFloat)getBackgroundViewHeight:(CGRect)cellFrame
97 | {
98 | if (self.backgroundViewHeight == JXCategoryViewAutomaticDimension) {
99 | return cellFrame.size.height;
100 | }
101 | return self.backgroundViewHeight;
102 | }
103 |
104 | - (CGFloat)getBackgroundViewCornerRadius:(CGRect)cellFrame {
105 | if (self.backgroundViewCornerRadius == JXCategoryViewAutomaticDimension) {
106 | return [self getBackgroundViewHeight:cellFrame]/2;
107 | }
108 | return self.backgroundViewCornerRadius;
109 | }
110 |
111 | @end
112 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/IndicatorViews/JXCategoryIndicatorBallView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryIndicatorBallView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/21.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorComponentView.h"
10 |
11 | @interface JXCategoryIndicatorBallView : JXCategoryIndicatorComponentView
12 |
13 | @property (nonatomic, assign) CGSize ballViewSize; //默认:CGSizeMake(15, 15)
14 |
15 | @property (nonatomic, assign) CGFloat ballScrollOffsetX; //小红点的偏移量 默认:20
16 |
17 | @property (nonatomic, strong) UIColor *ballViewColor; //默认为[UIColor redColor]
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/IndicatorViews/JXCategoryIndicatorComponentView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryComponentBaseView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "JXCategoryIndicatorProtocol.h"
11 | #import "JXCategoryViewDefines.h"
12 |
13 | @interface JXCategoryIndicatorComponentView : UIView
14 |
15 | @property (nonatomic, assign) JXCategoryComponentPosition componentPosition;
16 |
17 | @property (nonatomic, assign) CGFloat verticalMargin; //垂直方向边距;默认:0
18 |
19 | @property (nonatomic, assign) BOOL scrollEnabled; //手势滚动、点击切换的时候,是否允许滚动,默认YES
20 |
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/IndicatorViews/JXCategoryIndicatorComponentView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryComponentBaseView.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorComponentView.h"
10 |
11 | @implementation JXCategoryIndicatorComponentView
12 |
13 | - (instancetype)initWithFrame:(CGRect)frame
14 | {
15 | self = [super initWithFrame:frame];
16 | if (self) {
17 | _componentPosition = JXCategoryComponentPosition_Bottom;
18 | _scrollEnabled = YES;
19 | _verticalMargin = 0;
20 | }
21 | return self;
22 | }
23 |
24 | - (instancetype)initWithCoder:(NSCoder *)coder
25 | {
26 | self = [super initWithCoder:coder];
27 | if (self) {
28 | NSAssert(NO, @"Use initWithFrame");
29 | }
30 | return self;
31 | }
32 |
33 | #pragma mark - JXCategoryComponentProtocol
34 |
35 | - (void)jx_refreshState:(CGRect)selectedCellFrame {
36 |
37 | }
38 |
39 | - (void)jx_contentScrollViewDidScrollWithLeftCellFrame:(CGRect)leftCellFrame rightCellFrame:(CGRect)rightCellFrame selectedPosition:(JXCategoryCellClickedPosition)selectedPosition percent:(CGFloat)percent {
40 |
41 | }
42 |
43 | - (void)jx_selectedCell:(CGRect)cellFrame clickedRelativePosition:(JXCategoryCellClickedPosition)clickedRelativePosition {
44 |
45 | }
46 |
47 | @end
48 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/IndicatorViews/JXCategoryIndicatorImageView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryIndicatorImageView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorComponentView.h"
10 |
11 | @interface JXCategoryIndicatorImageView : JXCategoryIndicatorComponentView
12 |
13 | @property (nonatomic, strong, readonly) UIImageView *indicatorImageView;
14 |
15 | @property (nonatomic, assign) BOOL indicatorImageViewRollEnabled; //默认NO
16 |
17 | @property (nonatomic, assign) CGSize indicatorImageViewSize; //默认:CGSizeMake(30, 20)
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/IndicatorViews/JXCategoryIndicatorImageView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryIndicatorImageView.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorImageView.h"
10 | #import "JXCategoryFactory.h"
11 |
12 | @implementation JXCategoryIndicatorImageView
13 |
14 | - (instancetype)initWithFrame:(CGRect)frame
15 | {
16 | self = [super initWithFrame:frame];
17 | if (self) {
18 | _indicatorImageViewSize = CGSizeMake(30, 20);
19 | _indicatorImageViewRollEnabled = NO;
20 |
21 | _indicatorImageView = [[UIImageView alloc] init];
22 | self.indicatorImageView.frame = CGRectMake(0, 0, self.indicatorImageViewSize.width, self.indicatorImageViewSize.height);
23 | self.indicatorImageView.contentMode = UIViewContentModeScaleAspectFit;
24 | [self addSubview:self.indicatorImageView];
25 | }
26 | return self;
27 | }
28 |
29 | - (void)setIndicatorImageViewSize:(CGSize)indicatorImageViewSize {
30 | _indicatorImageViewSize = indicatorImageViewSize;
31 |
32 | self.indicatorImageView.frame = CGRectMake(0, 0, self.indicatorImageViewSize.width, self.indicatorImageViewSize.height);
33 | }
34 |
35 | #pragma mark - JXCategoryComponentProtocol
36 |
37 | - (void)jx_refreshState:(CGRect)selectedCellFrame {
38 | CGFloat x = selectedCellFrame.origin.x + (selectedCellFrame.size.width - self.indicatorImageViewSize.width)/2;
39 | CGFloat y = self.superview.bounds.size.height - self.indicatorImageViewSize.height - self.verticalMargin;
40 | if (self.componentPosition == JXCategoryComponentPosition_Top) {
41 | y = self.verticalMargin;
42 | }
43 | self.frame = CGRectMake(x, y, self.indicatorImageViewSize.width, self.indicatorImageViewSize.height);
44 | }
45 |
46 | - (void)jx_contentScrollViewDidScrollWithLeftCellFrame:(CGRect)leftCellFrame rightCellFrame:(CGRect)rightCellFrame selectedPosition:(JXCategoryCellClickedPosition)selectedPosition percent:(CGFloat)percent {
47 |
48 | CGFloat targetWidth = self.indicatorImageViewSize.width;
49 | CGFloat targetX = leftCellFrame.origin.x + (leftCellFrame.size.width - targetWidth)/2.0;
50 |
51 | if (percent == 0) {
52 | targetX = leftCellFrame.origin.x + (leftCellFrame.size.width - targetWidth)/2.0;
53 | }else {
54 | CGFloat leftX = leftCellFrame.origin.x + (leftCellFrame.size.width - targetWidth)/2;
55 | CGFloat rightX = rightCellFrame.origin.x + (rightCellFrame.size.width - targetWidth)/2;
56 | targetX = [JXCategoryFactory interpolationFrom:leftX to:rightX percent:percent];
57 | }
58 |
59 | //允许变动frame的情况:1、允许滚动;2、不允许滚动,但是已经通过手势滚动切换一页内容了;
60 | if (self.scrollEnabled == YES || (self.scrollEnabled == NO && percent == 0)) {
61 | CGRect frame = self.frame;
62 | frame.origin.x = targetX;
63 | self.frame = frame;
64 |
65 | if (self.indicatorImageViewRollEnabled) {
66 | self.indicatorImageView.transform = CGAffineTransformMakeRotation(M_PI*2*percent);
67 | }
68 | }
69 | }
70 |
71 | - (void)jx_selectedCell:(CGRect)cellFrame clickedRelativePosition:(JXCategoryCellClickedPosition)clickedRelativePosition {
72 | CGRect toFrame = self.frame;
73 | toFrame.origin.x = cellFrame.origin.x + (cellFrame.size.width - self.indicatorImageViewSize.width)/2;
74 | if (self.scrollEnabled) {
75 | [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
76 | self.frame = toFrame;
77 | } completion:^(BOOL finished) {
78 | }];
79 | if (self.indicatorImageViewRollEnabled) {
80 | CABasicAnimation *rotateAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
81 | rotateAnimation.toValue = @(M_PI*2*((clickedRelativePosition == JXCategoryCellClickedPosition_Left) ? -1 : 1));
82 | rotateAnimation.duration = 0.25;
83 | [self.indicatorImageView.layer addAnimation:rotateAnimation forKey:@"rotate"];
84 | }
85 | }else {
86 | self.frame = toFrame;
87 | }
88 | }
89 |
90 |
91 | @end
92 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/IndicatorViews/JXCategoryIndicatorLineView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryIndicatorLineView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorComponentView.h"
10 |
11 | typedef NS_ENUM(NSUInteger, JXCategoryIndicatorLineStyle) {
12 | JXCategoryIndicatorLineStyle_Normal = 0,
13 | JXCategoryIndicatorLineStyle_JD,
14 | JXCategoryIndicatorLineStyle_IQIYI,
15 | };
16 |
17 | @interface JXCategoryIndicatorLineView : JXCategoryIndicatorComponentView
18 |
19 | @property (nonatomic, assign) JXCategoryIndicatorLineStyle lineStyle;
20 |
21 | /**
22 | line滚动时x的偏移量,默认为10;
23 | lineStyle为JXCategoryLineStyle_IQIYI有用;
24 | */
25 | @property (nonatomic, assign) CGFloat lineScrollOffsetX;
26 |
27 | @property (nonatomic, assign) CGFloat indicatorLineViewHeight; //默认:3
28 |
29 | @property (nonatomic, assign) CGFloat indicatorLineWidth; //默认JXCategoryViewAutomaticDimension(与cellWidth相等)
30 |
31 | @property (nonatomic, assign) CGFloat indicatorLineViewCornerRadius; //默认JXCategoryViewAutomaticDimension (等于self.indicatorLineViewHeight/2)
32 |
33 | @property (nonatomic, strong) UIColor *indicatorLineViewColor; //默认为[UIColor redColor]
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/IndicatorViews/JXCategoryIndicatorTriangleView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryIndicatorTriangleView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorComponentView.h"
10 |
11 | @interface JXCategoryIndicatorTriangleView : JXCategoryIndicatorComponentView
12 |
13 | @property (nonatomic, assign) CGSize triangleViewSize; //默认:CGSizeMake(14, 10)
14 |
15 | @property (nonatomic, strong) UIColor *triangleViewColor; //默认:[UIColor redColor]
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/IndicatorViews/JXCategoryIndicatorTriangleView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryIndicatorTriangleView.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/17.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorTriangleView.h"
10 | #import "JXCategoryFactory.h"
11 |
12 | @interface JXCategoryIndicatorTriangleView ()
13 | @property (nonatomic, strong) CAShapeLayer *triangleLayer;
14 | @end
15 |
16 | @implementation JXCategoryIndicatorTriangleView
17 |
18 | - (instancetype)initWithFrame:(CGRect)frame
19 | {
20 | self = [super initWithFrame:frame];
21 | if (self) {
22 | _triangleViewSize = CGSizeMake(14, 10);
23 | _triangleViewColor = [UIColor redColor];
24 |
25 | _triangleLayer = [CAShapeLayer layer];
26 | [self.layer addSublayer:self.triangleLayer];
27 | }
28 | return self;
29 | }
30 |
31 | #pragma mark - JXCategoryComponentProtocol
32 |
33 | - (void)jx_refreshState:(CGRect)selectedCellFrame {
34 | CGFloat x = selectedCellFrame.origin.x + (selectedCellFrame.size.width - self.triangleViewSize.width)/2;
35 | CGFloat y = self.superview.bounds.size.height - self.triangleViewSize.height - self.verticalMargin;
36 | if (self.componentPosition == JXCategoryComponentPosition_Top) {
37 | y = self.verticalMargin;
38 | }
39 | self.frame = CGRectMake(x, y, self.triangleViewSize.width, self.triangleViewSize.height);
40 |
41 | [CATransaction begin];
42 | [CATransaction setDisableActions:NO];
43 | self.triangleLayer.fillColor = self.triangleViewColor.CGColor;
44 | self.triangleLayer.frame = self.bounds;
45 | UIBezierPath *path = [UIBezierPath bezierPath];
46 | if (self.componentPosition == JXCategoryComponentPosition_Bottom) {
47 | [path moveToPoint:CGPointMake(self.bounds.size.width/2, 0)];
48 | [path addLineToPoint:CGPointMake(0, self.bounds.size.height)];
49 | [path addLineToPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height)];
50 | }else {
51 | [path moveToPoint:CGPointMake(0, 0)];
52 | [path addLineToPoint:CGPointMake(self.bounds.size.width, 0)];
53 | [path addLineToPoint:CGPointMake(self.bounds.size.width/2, self.bounds.size.height)];
54 | }
55 | [path closePath];
56 | self.triangleLayer.path = path.CGPath;
57 | [CATransaction commit];
58 | }
59 |
60 | - (void)jx_contentScrollViewDidScrollWithLeftCellFrame:(CGRect)leftCellFrame rightCellFrame:(CGRect)rightCellFrame selectedPosition:(JXCategoryCellClickedPosition)selectedPosition percent:(CGFloat)percent {
61 |
62 | CGFloat targetWidth = self.triangleViewSize.width;
63 | CGFloat targetX = leftCellFrame.origin.x + (leftCellFrame.size.width - targetWidth)/2.0;
64 |
65 | if (percent == 0) {
66 | targetX = leftCellFrame.origin.x + (leftCellFrame.size.width - targetWidth)/2.0;
67 | }else {
68 | CGFloat leftX = leftCellFrame.origin.x + (leftCellFrame.size.width - targetWidth)/2;
69 | CGFloat rightX = rightCellFrame.origin.x + (rightCellFrame.size.width - targetWidth)/2;
70 | targetX = [JXCategoryFactory interpolationFrom:leftX to:rightX percent:percent];
71 | }
72 |
73 | //允许变动frame的情况:1、允许滚动;2、不允许滚动,但是已经通过手势滚动切换一页内容了;
74 | if (self.scrollEnabled == YES || (self.scrollEnabled == NO && percent == 0)) {
75 | CGRect frame = self.frame;
76 | frame.origin.x = targetX;
77 | self.frame = frame;
78 | }
79 | }
80 |
81 | - (void)jx_selectedCell:(CGRect)cellFrame clickedRelativePosition:(JXCategoryCellClickedPosition)clickedRelativePosition {
82 | CGRect toFrame = self.frame;
83 | toFrame.origin.x = cellFrame.origin.x + (cellFrame.size.width - self.triangleViewSize.width)/2;
84 | if (self.scrollEnabled) {
85 | [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
86 | self.frame = toFrame;
87 | } completion:^(BOOL finished) {
88 | }];
89 | }else {
90 | self.frame = toFrame;
91 | }
92 | }
93 |
94 | @end
95 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/JXCategoryIndicatorCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryComponetCell.h
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/7/25.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryBaseCell.h"
10 |
11 | @interface JXCategoryIndicatorCell : JXCategoryBaseCell
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/JXCategoryIndicatorCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryComponetCell.m
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/7/25.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorCell.h"
10 | #import "JXCategoryIndicatorCellModel.h"
11 |
12 | @interface JXCategoryIndicatorCell ()
13 | @property (nonatomic, strong) UIView *separatorLine;
14 | @end
15 |
16 | @implementation JXCategoryIndicatorCell
17 |
18 | - (void)initializeViews
19 | {
20 | [super initializeViews];
21 |
22 | self.separatorLine = [[UIView alloc] init];
23 | self.separatorLine.hidden = YES;
24 | [self.contentView addSubview:self.separatorLine];
25 | }
26 |
27 | - (void)layoutSubviews
28 | {
29 | [super layoutSubviews];
30 |
31 | JXCategoryIndicatorCellModel *model = (JXCategoryIndicatorCellModel *)self.cellModel;
32 | CGFloat lineWidth = model.separatorLineSize.width;
33 | CGFloat lineHeight = model.separatorLineSize.height;
34 |
35 | self.separatorLine.frame = CGRectMake(self.bounds.size.width - lineWidth + self.cellModel.cellSpacing/2, (self.bounds.size.height - lineHeight)/2.0, lineWidth, lineHeight);
36 | }
37 |
38 | - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
39 | [super reloadData:cellModel];
40 |
41 | JXCategoryIndicatorCellModel *model = (JXCategoryIndicatorCellModel *)cellModel;
42 | self.separatorLine.backgroundColor = model.separatorLineColor;
43 | self.separatorLine.hidden = !model.sepratorLineShowEnabled;
44 |
45 | if (model.cellBackgroundColorGradientEnabled) {
46 | if (model.selected) {
47 | self.contentView.backgroundColor = model.cellBackgroundSelectedColor;
48 | }else {
49 | self.contentView.backgroundColor = model.cellBackgroundUnselectedColor;
50 | }
51 | }
52 | }
53 |
54 | @end
55 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/JXCategoryIndicatorCellModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryComponentCellModel.h
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/7/25.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "JXCategoryBaseCellModel.h"
11 |
12 | @interface JXCategoryIndicatorCellModel : JXCategoryBaseCellModel
13 |
14 | @property (nonatomic, assign) BOOL sepratorLineShowEnabled;
15 |
16 | @property (nonatomic, strong) UIColor *separatorLineColor;
17 |
18 | @property (nonatomic, assign) CGSize separatorLineSize;
19 |
20 | @property (nonatomic, assign) CGRect backgroundViewMaskFrame;
21 |
22 | @property (nonatomic, assign) BOOL cellBackgroundColorGradientEnabled;
23 |
24 | @property (nonatomic, strong) UIColor *cellBackgroundUnselectedColor;
25 |
26 | @property (nonatomic, strong) UIColor *cellBackgroundSelectedColor;
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/JXCategoryIndicatorCellModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryComponentCellModel.m
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/7/25.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorCellModel.h"
10 |
11 | @implementation JXCategoryIndicatorCellModel
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Indicator/JXCategoryIndicatorView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryComponentView.h
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/7/25.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryBaseView.h"
10 | #import "JXCategoryIndicatorCell.h"
11 | #import "JXCategoryIndicatorCellModel.h"
12 | #import "JXCategoryIndicatorProtocol.h"
13 |
14 | @interface JXCategoryIndicatorView : JXCategoryBaseView
15 |
16 | @property (nonatomic, strong) NSArray *> *indicators;
17 |
18 | //----------------------ellBackgroundColor-----------------------//
19 | @property (nonatomic, assign) BOOL cellBackgroundColorGradientEnabled; //默认:NO
20 |
21 | @property (nonatomic, strong) UIColor *cellBackgroundUnselectedColor; //默认:[UIColor clearColor]
22 |
23 | @property (nonatomic, strong) UIColor *cellBackgroundSelectedColor; //默认:[UIColor grayColor]
24 |
25 | //----------------------separatorLine-----------------------//
26 | @property (nonatomic, assign) BOOL separatorLineShowEnabled; //默认为NO
27 |
28 | @property (nonatomic, strong) UIColor *separatorLineColor; //默认为[UIColor lightGrayColor]
29 |
30 | @property (nonatomic, assign) CGSize separatorLineSize; //默认为CGSizeMake(1/[UIScreen mainScreen].scale, 20)
31 |
32 | /**
33 | 当contentScrollView滚动时候,处理跟随手势的过渡效果。
34 | 根据cellModel的左右位置、是否选中、ratio进行过滤数据计算。
35 |
36 | @param leftCellModel 左边的cellModel
37 | @param rightCellModel 右边的cellModel
38 | @param ratio 从左往右方向计算的百分比
39 | */
40 | - (void)refreshLeftCellModel:(JXCategoryBaseCellModel *)leftCellModel rightCellModel:(JXCategoryBaseCellModel *)rightCellModel ratio:(CGFloat)ratio NS_REQUIRES_SUPER;
41 |
42 | @end
43 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/JXCategoryView.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #import "JXCategoryBaseView.h"
4 | #import "JXCategoryIndicatorView.h"
5 | #import "JXCategoryTitleView.h"
6 | #import "JXCategoryImageView.h"
7 | #import "JXCategoryTitleImageView.h"
8 | #import "JXCategoryNumberView.h"
9 | #import "JXCategoryDotView.h"
10 |
11 | #import "JXCategoryFactory.h"
12 | #import "JXCategoryIndicatorProtocol.h"
13 | #import "JXCategoryViewDefines.h"
14 | #import "JXCategoryListVCContainerView.h"
15 |
16 | #import "JXCategoryIndicatorComponentView.h"
17 | #import "JXCategoryIndicatorLineView.h"
18 | #import "JXCategoryIndicatorTriangleView.h"
19 | #import "JXCategoryIndicatorImageView.h"
20 | #import "JXCategoryIndicatorBackgroundView.h"
21 | #import "JXCategoryIndicatorBallView.h"
22 |
23 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Number/JXCategoryNumberCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryNumberCell.h
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/4/9.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleCell.h"
10 |
11 | @interface JXCategoryNumberCell : JXCategoryTitleCell
12 | @property (nonatomic, strong) UILabel *numberLabel;
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Number/JXCategoryNumberCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryNumberCell.m
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/4/9.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryNumberCell.h"
10 | #import "JXCategoryNumberCellModel.h"
11 |
12 | @interface JXCategoryNumberCell ()
13 |
14 | @end
15 |
16 | @implementation JXCategoryNumberCell
17 |
18 | - (void)initializeViews {
19 | [super initializeViews];
20 |
21 | self.numberLabel = ({
22 | UILabel *label = [[UILabel alloc] init];
23 | label.textColor = [UIColor whiteColor];
24 | label.backgroundColor = [UIColor colorWithRed:241/255.0 green:147/255.0 blue:95/255.0 alpha:1];
25 | label.font = [UIFont systemFontOfSize:11];
26 | label.textAlignment = NSTextAlignmentCenter;
27 | label.layer.cornerRadius = 7;
28 | label.layer.masksToBounds = YES;
29 | label;
30 | });
31 | [self.contentView addSubview:self.numberLabel];
32 | }
33 |
34 | - (void)layoutSubviews {
35 | [super layoutSubviews];
36 |
37 | [self.numberLabel sizeToFit];
38 | self.numberLabel.bounds = CGRectMake(0, 0, self.numberLabel.bounds.size.width + 10, 14);
39 | self.numberLabel.center = CGPointMake(CGRectGetMaxX(self.titleLabel.frame), CGRectGetMinY(self.titleLabel.frame));
40 | }
41 |
42 | - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
43 | [super reloadData:cellModel];
44 |
45 | JXCategoryNumberCellModel *myCellModel = (JXCategoryNumberCellModel *)cellModel;
46 | self.numberLabel.hidden = myCellModel.count == 0;
47 | self.numberLabel.text = [NSString stringWithFormat:@"%ld", (long)myCellModel.count];
48 | if (myCellModel.count >= 1000) {
49 | self.numberLabel.text = @"999+";
50 | }
51 |
52 | [self setNeedsLayout];
53 | [self layoutIfNeeded];
54 | }
55 |
56 | @end
57 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Number/JXCategoryNumberCellModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryNumberCellModel.h
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/4/24.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleCellModel.h"
10 |
11 | @interface JXCategoryNumberCellModel : JXCategoryTitleCellModel
12 |
13 | @property (nonatomic, assign) NSInteger count;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Number/JXCategoryNumberCellModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryNumberCellModel.m
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/4/24.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryNumberCellModel.h"
10 |
11 | @implementation JXCategoryNumberCellModel
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Number/JXCategoryNumberView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryNumberView.h
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/4/9.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleView.h"
10 | #import "JXCategoryNumberCell.h"
11 | #import "JXCategoryNumberCellModel.h"
12 |
13 | @interface JXCategoryNumberView : JXCategoryTitleView
14 |
15 | /**
16 | 需要与titles的count对应
17 | */
18 | @property (nonatomic, strong) NSArray *counts;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Number/JXCategoryNumberView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryNumberView.m
3 | // DQGuess
4 | //
5 | // Created by jiaxin on 2018/4/9.
6 | // Copyright © 2018年 jingbo. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryNumberView.h"
10 |
11 | @implementation JXCategoryNumberView
12 |
13 | - (void)initializeData {
14 | [super initializeData];
15 |
16 | self.cellSpacing = 25;
17 | }
18 |
19 | - (Class)preferredCellClass {
20 | return [JXCategoryNumberCell class];
21 | }
22 |
23 | - (void)refreshDataSource {
24 | NSMutableArray *tempArray = [NSMutableArray array];
25 | for (int i = 0; i < self.titles.count; i++) {
26 | JXCategoryNumberCellModel *cellModel = [[JXCategoryNumberCellModel alloc] init];
27 | [tempArray addObject:cellModel];
28 | }
29 | self.dataSource = tempArray;
30 | }
31 |
32 | - (void)refreshCellModel:(JXCategoryBaseCellModel *)cellModel index:(NSInteger)index {
33 | [super refreshCellModel:cellModel index:index];
34 |
35 | JXCategoryNumberCellModel *myCellModel = (JXCategoryNumberCellModel *)cellModel;
36 | myCellModel.count = [self.counts[index] integerValue];
37 | }
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Title/JXCategoryTitleCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryTitleCell.h
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/15.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorCell.h"
10 |
11 | @interface JXCategoryTitleCell : JXCategoryIndicatorCell
12 |
13 | @property (nonatomic, strong) UILabel *titleLabel;
14 |
15 | @property (nonatomic, strong) UILabel *maskTitleLabel;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Title/JXCategoryTitleCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryTitleCell.m
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/15.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleCell.h"
10 | #import "JXCategoryTitleCellModel.h"
11 |
12 | @interface JXCategoryTitleCell ()
13 | @property (nonatomic, strong) CALayer *maskLayer;
14 |
15 | @end
16 |
17 | @implementation JXCategoryTitleCell
18 |
19 | - (void)initializeViews
20 | {
21 | [super initializeViews];
22 |
23 | _titleLabel = [[UILabel alloc] init];
24 | self.titleLabel.textAlignment = NSTextAlignmentCenter;
25 | [self.contentView addSubview:self.titleLabel];
26 |
27 | _maskTitleLabel = [[UILabel alloc] init];
28 | _maskTitleLabel.hidden = YES;
29 | self.maskTitleLabel.textAlignment = NSTextAlignmentCenter;
30 | [self.contentView addSubview:self.maskTitleLabel];
31 |
32 | _maskLayer = [CALayer layer];
33 | self.maskLayer.backgroundColor = [UIColor redColor].CGColor;
34 | self.maskTitleLabel.layer.mask = self.maskLayer;
35 | }
36 |
37 | - (void)layoutSubviews {
38 | [super layoutSubviews];
39 |
40 | self.titleLabel.center = self.contentView.center;
41 | self.maskTitleLabel.center = self.contentView.center;
42 | }
43 |
44 | - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
45 | [super reloadData:cellModel];
46 |
47 | JXCategoryTitleCellModel *myCellModel = (JXCategoryTitleCellModel *)cellModel;
48 |
49 | CGFloat pointSize = myCellModel.titleFont.pointSize;
50 | UIFontDescriptor *fontDescriptor = myCellModel.titleFont.fontDescriptor;
51 | if (myCellModel.selected) {
52 | fontDescriptor = myCellModel.titleSelectedFont.fontDescriptor;
53 | pointSize = myCellModel.titleSelectedFont.pointSize;
54 | }
55 | if (myCellModel.titleLabelZoomEnabled) {
56 | self.titleLabel.font = [UIFont fontWithDescriptor:fontDescriptor size:pointSize*myCellModel.titleLabelZoomScale];
57 | self.maskTitleLabel.font = [UIFont fontWithDescriptor:fontDescriptor size:pointSize*myCellModel.titleLabelZoomScale];
58 | }else {
59 | self.titleLabel.font = [UIFont fontWithDescriptor:fontDescriptor size:pointSize];
60 | self.maskTitleLabel.font = [UIFont fontWithDescriptor:fontDescriptor size:pointSize];
61 | }
62 |
63 | self.maskTitleLabel.hidden = !myCellModel.titleLabelMaskEnabled;
64 | if (myCellModel.titleLabelMaskEnabled) {
65 | self.titleLabel.textColor = myCellModel.titleColor;
66 | self.maskTitleLabel.font = myCellModel.titleFont;
67 | self.maskTitleLabel.textColor = myCellModel.titleSelectedColor;
68 |
69 | self.maskTitleLabel.text = myCellModel.title;
70 | [self.maskTitleLabel sizeToFit];
71 |
72 | CGRect frame = myCellModel.backgroundViewMaskFrame;
73 | frame.origin.x -= (self.contentView.bounds.size.width - self.maskTitleLabel.bounds.size.width)/2;
74 | frame.origin.y = 0;
75 | [CATransaction begin];
76 | [CATransaction setDisableActions:YES];
77 | self.maskLayer.frame = frame;
78 | [CATransaction commit];
79 | }else {
80 | if (myCellModel.selected) {
81 | self.titleLabel.textColor = myCellModel.titleSelectedColor;
82 | }else {
83 | self.titleLabel.textColor = myCellModel.titleColor;
84 | }
85 | }
86 |
87 | self.titleLabel.text = myCellModel.title;
88 | [self.titleLabel sizeToFit];
89 | [self setNeedsLayout];
90 | [self layoutIfNeeded];
91 | }
92 |
93 |
94 | @end
95 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Title/JXCategoryTitleCellModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryTitleCellModel.h
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/15.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorCellModel.h"
10 | #import
11 |
12 | @interface JXCategoryTitleCellModel : JXCategoryIndicatorCellModel
13 |
14 | @property (nonatomic, copy) NSString *title;
15 |
16 | @property (nonatomic, strong) UIColor *titleColor;
17 |
18 | @property (nonatomic, strong) UIColor *titleSelectedColor;
19 |
20 | @property (nonatomic, strong) UIFont *titleFont;
21 |
22 | @property (nonatomic, strong) UIFont *titleSelectedFont;
23 |
24 | @property (nonatomic, assign) BOOL titleLabelMaskEnabled;
25 |
26 | @property (nonatomic, strong) CALayer *backgroundEllipseLayer;
27 |
28 | @property (nonatomic, assign) BOOL titleLabelZoomEnabled;
29 |
30 | @property (nonatomic, assign) CGFloat titleLabelZoomScale;
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Title/JXCategoryTitleCellModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryTitleCellModel.m
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/15.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleCellModel.h"
10 |
11 | @implementation JXCategoryTitleCellModel
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Title/JXCategoryTitleView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryView.h
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/15.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryIndicatorView.h"
10 | #import "JXCategoryTitleCell.h"
11 | #import "JXCategoryTitleCellModel.h"
12 |
13 | @interface JXCategoryTitleView : JXCategoryIndicatorView
14 |
15 | @property (nonatomic, strong) NSArray *titles;
16 |
17 | @property (nonatomic, strong) UIColor *titleColor; //默认:[UIColor blackColor]
18 |
19 | @property (nonatomic, strong) UIColor *titleSelectedColor; //默认:[UIColor redColor]
20 |
21 | @property (nonatomic, strong) UIFont *titleFont; //默认:[UIFont systemFontOfSize:15]
22 |
23 | @property (nonatomic, strong) UIFont *titleSelectedFont; //文字被选中的字体。默认:与titleFont一样
24 |
25 | @property (nonatomic, assign) BOOL titleColorGradientEnabled; //默认:NO,title的颜色是否渐变过渡
26 |
27 | @property (nonatomic, assign) BOOL titleLabelMaskEnabled; //默认:NO,titleLabel是否遮罩过滤。(需要backgroundEllipseLayerShowEnabled = YES)
28 |
29 | //----------------------titleLabelZoomEnabled-----------------------//
30 | @property (nonatomic, assign) BOOL titleLabelZoomEnabled; //默认为NO
31 |
32 | @property (nonatomic, assign) BOOL titleLabelZoomScrollGradientEnabled; //手势滚动中,是否需要更新状态。默认为YES
33 |
34 | @property (nonatomic, assign) CGFloat titleLabelZoomScale; //默认1.2,titleLabelZoomEnabled为YES才生效
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/Title/JXCategoryTitleView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryView.m
3 | // UI系列测试
4 | //
5 | // Created by jiaxin on 2018/3/15.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleView.h"
10 | #import "JXCategoryFactory.h"
11 |
12 | @interface JXCategoryTitleView ()
13 |
14 | @end
15 |
16 | @implementation JXCategoryTitleView
17 |
18 | - (void)initializeData
19 | {
20 | [super initializeData];
21 |
22 | _titleLabelZoomEnabled = NO;
23 | _titleLabelZoomScale = 1.2;
24 | _titleColor = [UIColor blackColor];
25 | _titleSelectedColor = [UIColor redColor];
26 | _titleFont = [UIFont systemFontOfSize:15];
27 | _titleColorGradientEnabled = NO;
28 | _titleLabelMaskEnabled = NO;
29 | _titleLabelZoomScrollGradientEnabled = YES;
30 | }
31 |
32 | - (UIFont *)titleSelectedFont {
33 | if (_titleSelectedFont != nil) {
34 | return _titleSelectedFont;
35 | }
36 | return self.titleFont;
37 | }
38 |
39 | #pragma mark - Override
40 |
41 | - (Class)preferredCellClass {
42 | return [JXCategoryTitleCell class];
43 | }
44 |
45 | - (void)refreshDataSource {
46 | NSMutableArray *tempArray = [NSMutableArray array];
47 | for (int i = 0; i < self.titles.count; i++) {
48 | JXCategoryTitleCellModel *cellModel = [[JXCategoryTitleCellModel alloc] init];
49 | [tempArray addObject:cellModel];
50 | }
51 | self.dataSource = tempArray;
52 | }
53 |
54 | - (void)refreshSelectedCellModel:(JXCategoryBaseCellModel *)selectedCellModel unselectedCellModel:(JXCategoryBaseCellModel *)unselectedCellModel {
55 | [super refreshSelectedCellModel:selectedCellModel unselectedCellModel:unselectedCellModel];
56 |
57 | JXCategoryTitleCellModel *myUnselectedCellModel = (JXCategoryTitleCellModel *)unselectedCellModel;
58 | myUnselectedCellModel.titleColor = self.titleColor;
59 | myUnselectedCellModel.titleSelectedColor = self.titleSelectedColor;
60 | myUnselectedCellModel.titleLabelZoomScale = 1.0;
61 |
62 | JXCategoryTitleCellModel *myselectedCellModel = (JXCategoryTitleCellModel *)selectedCellModel;
63 | myselectedCellModel.titleColor = self.titleColor;
64 | myselectedCellModel.titleSelectedColor = self.titleSelectedColor;
65 | myselectedCellModel.titleLabelZoomScale = self.titleLabelZoomScale;
66 | }
67 |
68 | - (void)refreshLeftCellModel:(JXCategoryBaseCellModel *)leftCellModel rightCellModel:(JXCategoryBaseCellModel *)rightCellModel ratio:(CGFloat)ratio {
69 | [super refreshLeftCellModel:leftCellModel rightCellModel:rightCellModel ratio:ratio];
70 |
71 | JXCategoryTitleCellModel *leftModel = (JXCategoryTitleCellModel *)leftCellModel;
72 | JXCategoryTitleCellModel *rightModel = (JXCategoryTitleCellModel *)rightCellModel;
73 |
74 | if (self.titleLabelZoomEnabled && self.titleLabelZoomScrollGradientEnabled) {
75 | leftModel.titleLabelZoomScale = [JXCategoryFactory interpolationFrom:self.titleLabelZoomScale to:1.0 percent:ratio];
76 | rightModel.titleLabelZoomScale = [JXCategoryFactory interpolationFrom:1.0 to:self.titleLabelZoomScale percent:ratio];
77 | }
78 |
79 | if (self.titleColorGradientEnabled) {
80 | //处理颜色渐变
81 | if (leftModel.selected) {
82 | leftModel.titleSelectedColor = [JXCategoryFactory interpolationColorFrom:self.titleSelectedColor to:self.titleColor percent:ratio];
83 | leftModel.titleColor = self.titleColor;
84 | }else {
85 | leftModel.titleColor = [JXCategoryFactory interpolationColorFrom:self.titleSelectedColor to:self.titleColor percent:ratio];
86 | leftModel.titleSelectedColor = self.titleSelectedColor;
87 | }
88 | if (rightModel.selected) {
89 | rightModel.titleSelectedColor = [JXCategoryFactory interpolationColorFrom:self.titleColor to:self.titleSelectedColor percent:ratio];
90 | rightModel.titleColor = self.titleColor;
91 | }else {
92 | rightModel.titleColor = [JXCategoryFactory interpolationColorFrom:self.titleColor to:self.titleSelectedColor percent:ratio];
93 | rightModel.titleSelectedColor = self.titleSelectedColor;
94 | }
95 | }
96 | }
97 |
98 | - (CGFloat)preferredCellWidthAtIndex:(NSInteger)index {
99 | if (self.cellWidth == JXCategoryViewAutomaticDimension) {
100 | return ceilf([self.titles[index] boundingRectWithSize:CGSizeMake(MAXFLOAT, self.bounds.size.height) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : self.titleFont} context:nil].size.width);
101 | }else {
102 | return self.cellWidth;
103 | }
104 | }
105 |
106 | - (void)refreshCellModel:(JXCategoryBaseCellModel *)cellModel index:(NSInteger)index {
107 | [super refreshCellModel:cellModel index:index];
108 |
109 | JXCategoryTitleCellModel *model = (JXCategoryTitleCellModel *)cellModel;
110 | model.titleFont = self.titleFont;
111 | model.titleSelectedFont = self.titleSelectedFont;
112 | model.titleColor = self.titleColor;
113 | model.titleSelectedColor = self.titleSelectedColor;
114 | model.title = self.titles[index];
115 | model.titleLabelMaskEnabled = self.titleLabelMaskEnabled;
116 | model.titleLabelZoomEnabled = self.titleLabelZoomEnabled;
117 | model.titleLabelZoomScale = 1.0;
118 | if (index == self.selectedIndex) {
119 | model.titleLabelZoomScale = self.titleLabelZoomScale;
120 | }
121 | }
122 |
123 | @end
124 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/TitleImage/JXCategoryTitleImageCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryImageCell.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/8.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleCell.h"
10 |
11 | @interface JXCategoryTitleImageCell : JXCategoryTitleCell
12 |
13 | @property (nonatomic, strong) UIImageView *imageView;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/TitleImage/JXCategoryTitleImageCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryImageCell.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/8.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleImageCell.h"
10 | #import "JXCategoryTitleImageCellModel.h"
11 |
12 | @interface JXCategoryTitleImageCell()
13 |
14 | @end
15 |
16 | @implementation JXCategoryTitleImageCell
17 |
18 | - (void)initializeViews {
19 | [super initializeViews];
20 |
21 | _imageView = [[UIImageView alloc] init];
22 | _imageView.contentMode = UIViewContentModeScaleAspectFit;
23 | [self.contentView addSubview:_imageView];
24 | }
25 |
26 | - (void)layoutSubviews {
27 | [super layoutSubviews];
28 |
29 | JXCategoryTitleImageCellModel *myCellModel = (JXCategoryTitleImageCellModel *)self.cellModel;
30 | self.titleLabel.hidden = NO;
31 | self.imageView.hidden = NO;
32 | CGSize imageSize = myCellModel.imageSize;
33 | self.imageView.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height);
34 | switch (myCellModel.imageType) {
35 |
36 | case JXCategoryTitleImageType_TopImage:
37 | {
38 | CGFloat contentHeight = imageSize.height + myCellModel.titleImageSpacing + self.titleLabel.bounds.size.height;
39 | self.imageView.center = CGPointMake(self.contentView.center.x, (self.contentView.bounds.size.height - contentHeight)/2 + imageSize.height/2);
40 | self.titleLabel.center = CGPointMake(self.contentView.center.x, CGRectGetMaxY(self.imageView.frame) + myCellModel.titleImageSpacing + self.titleLabel.bounds.size.height/2);
41 | }
42 | break;
43 |
44 | case JXCategoryTitleImageType_LeftImage:
45 | {
46 | CGFloat contentWidth = imageSize.width + myCellModel.titleImageSpacing + self.titleLabel.bounds.size.width;
47 | self.imageView.center = CGPointMake((self.contentView.bounds.size.width - contentWidth)/2 + imageSize.width/2, self.contentView.center.y);
48 | self.titleLabel.center = CGPointMake(CGRectGetMaxX(self.imageView.frame) + myCellModel.titleImageSpacing + self.titleLabel.bounds.size.width/2, self.contentView.center.y);
49 | }
50 | break;
51 |
52 | case JXCategoryTitleImageType_BottomImage:
53 | {
54 | CGFloat contentHeight = imageSize.height + myCellModel.titleImageSpacing + self.titleLabel.bounds.size.height;
55 | self.titleLabel.center = CGPointMake(self.contentView.center.x, (self.contentView.bounds.size.height - contentHeight)/2 + self.titleLabel.bounds.size.height/2);
56 | self.imageView.center = CGPointMake(self.contentView.center.x, CGRectGetMaxY(self.titleLabel.frame) + myCellModel.titleImageSpacing + imageSize.height/2);
57 | }
58 | break;
59 |
60 | case JXCategoryTitleImageType_RightImage:
61 | {
62 | CGFloat contentWidth = imageSize.width + myCellModel.titleImageSpacing + self.titleLabel.bounds.size.width;
63 | self.titleLabel.center = CGPointMake((self.contentView.bounds.size.width - contentWidth)/2 + self.titleLabel.bounds.size.width/2, self.contentView.center.y);
64 | self.imageView.center = CGPointMake(CGRectGetMaxX(self.titleLabel.frame) + myCellModel.titleImageSpacing + imageSize.width/2, self.contentView.center.y);
65 | }
66 | break;
67 |
68 | case JXCategoryTitleImageType_OnlyImage:
69 | {
70 | self.titleLabel.hidden = YES;
71 | self.imageView.center = self.contentView.center;
72 | }
73 | break;
74 |
75 | case JXCategoryTitleImageType_OnlyTitle:
76 | {
77 | self.imageView.hidden = YES;
78 | self.titleLabel.center = self.contentView.center;
79 | }
80 | break;
81 |
82 | default:
83 | break;
84 | }
85 | }
86 |
87 | - (void)reloadData:(JXCategoryBaseCellModel *)cellModel {
88 | [super reloadData:cellModel];
89 |
90 | JXCategoryTitleImageCellModel *myCellModel = (JXCategoryTitleImageCellModel *)cellModel;
91 | if (myCellModel.imageName != nil) {
92 | self.imageView.image = [UIImage imageNamed:myCellModel.imageName];
93 | }else if (myCellModel.imageURL != nil) {
94 | if (myCellModel.loadImageCallback != nil) {
95 | myCellModel.loadImageCallback(self.imageView, myCellModel.imageURL);
96 | }
97 | }
98 | if (myCellModel.selected) {
99 | if (myCellModel.selectedImageName != nil) {
100 | self.imageView.image = [UIImage imageNamed:myCellModel.selectedImageName];
101 | }else if (myCellModel.selectedImageURL != nil) {
102 | if (myCellModel.loadImageCallback != nil) {
103 | myCellModel.loadImageCallback(self.imageView, myCellModel.selectedImageURL);
104 | }
105 | }
106 | }
107 |
108 | if (myCellModel.imageZoomEnabled) {
109 | self.imageView.transform = CGAffineTransformMakeScale(myCellModel.imageZoomScale, myCellModel.imageZoomScale);
110 | }else {
111 | self.imageView.transform = CGAffineTransformIdentity;
112 | }
113 |
114 | [self setNeedsLayout];
115 | [self layoutIfNeeded];
116 | }
117 |
118 |
119 | @end
120 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/TitleImage/JXCategoryTitleImageCellModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryTitleImageCellModel.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/8.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleCellModel.h"
10 |
11 | typedef NS_ENUM(NSUInteger, JXCategoryTitleImageType) {
12 | JXCategoryTitleImageType_TopImage = 0,
13 | JXCategoryTitleImageType_LeftImage,
14 | JXCategoryTitleImageType_BottomImage,
15 | JXCategoryTitleImageType_RightImage,
16 | JXCategoryTitleImageType_OnlyImage,
17 | JXCategoryTitleImageType_OnlyTitle,
18 | };
19 |
20 | @interface JXCategoryTitleImageCellModel : JXCategoryTitleCellModel
21 |
22 | @property (nonatomic, assign) JXCategoryTitleImageType imageType;
23 |
24 | @property (nonatomic, copy) void(^loadImageCallback)(UIImageView *imageView, NSURL *imageURL);
25 |
26 | @property (nonatomic, copy) NSString *imageName; //加载bundle内的图片
27 |
28 | @property (nonatomic, strong) NSURL *imageURL; //图片URL
29 |
30 | @property (nonatomic, copy) NSString *selectedImageName;
31 |
32 | @property (nonatomic, strong) NSURL *selectedImageURL;
33 |
34 | @property (nonatomic, assign) CGSize imageSize; //默认CGSizeMake(20, 20)
35 |
36 | @property (nonatomic, assign) CGFloat titleImageSpacing; //titleLabel和ImageView的间距,默认5
37 |
38 | @property (nonatomic, assign) BOOL imageZoomEnabled;
39 |
40 | @property (nonatomic, assign) CGFloat imageZoomScale;
41 |
42 | @end
43 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/TitleImage/JXCategoryTitleImageCellModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryTitleImageCellModel.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/8.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleImageCellModel.h"
10 |
11 | @implementation JXCategoryTitleImageCellModel
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/TitleImage/JXCategoryTitleImageView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryImageView.h
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/8.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleView.h"
10 | #import "JXCategoryTitleImageCell.h"
11 | #import "JXCategoryTitleImageCellModel.h"
12 |
13 | @interface JXCategoryTitleImageView : JXCategoryTitleView
14 |
15 | @property (nonatomic, strong) NSArray *imageNames;
16 |
17 | @property (nonatomic, strong) NSArray *imageURLs;
18 |
19 | @property (nonatomic, strong) NSArray *selectedImageNames;
20 |
21 | @property (nonatomic, strong) NSArray *selectedImageURLs;
22 |
23 | @property (nonatomic, strong) NSArray *imageTypes; //默认JXCategoryTitleImageType_LeftImage
24 |
25 | @property (nonatomic, copy) void(^loadImageCallback)(UIImageView *imageView, NSURL *imageURL); //使用imageURL从远端下载图片进行加载,建议使用SDWebImage等第三方库进行下载。
26 |
27 | @property (nonatomic, assign) CGSize imageSize; //默认CGSizeMake(20, 20)
28 |
29 | @property (nonatomic, assign) CGFloat titleImageSpacing; //titleLabel和ImageView的间距,默认5
30 |
31 | @property (nonatomic, assign) BOOL imageZoomEnabled; //默认为NO
32 |
33 | @property (nonatomic, assign) CGFloat imageZoomScale; //默认1.2,imageZoomEnabled为YES才生效
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/JXPageListView/JXCategoryView/TitleImage/JXCategoryTitleImageView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXCategoryImageView.m
3 | // JXCategoryView
4 | //
5 | // Created by jiaxin on 2018/8/8.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "JXCategoryTitleImageView.h"
10 | #import "JXCategoryTitleImageCell.h"
11 | #import "JXCategoryTitleImageCellModel.h"
12 | #import "JXCategoryFactory.h"
13 |
14 | @implementation JXCategoryTitleImageView
15 |
16 | - (void)dealloc
17 | {
18 | self.loadImageCallback = nil;
19 | }
20 |
21 | - (void)initializeData {
22 | [super initializeData];
23 |
24 | _imageSize = CGSizeMake(20, 20);
25 | _titleImageSpacing = 5;
26 | _imageZoomEnabled = NO;
27 | _imageZoomScale = 1.2;
28 | }
29 |
30 | - (Class)preferredCellClass {
31 | return [JXCategoryTitleImageCell class];
32 | }
33 |
34 | - (void)refreshDataSource {
35 | NSMutableArray *tempArray = [NSMutableArray array];
36 | for (int i = 0; i < self.titles.count; i++) {
37 | JXCategoryTitleImageCellModel *cellModel = [[JXCategoryTitleImageCellModel alloc] init];
38 | [tempArray addObject:cellModel];
39 | }
40 | if (self.imageTypes == nil || self.imageTypes.count == 0) {
41 | NSMutableArray *types = [NSMutableArray array];
42 | for (int i = 0; i < self.titles.count; i++) {
43 | [types addObject:@(JXCategoryTitleImageType_LeftImage)];
44 | }
45 | self.imageTypes = types;
46 | }
47 | self.dataSource = tempArray;
48 | }
49 |
50 | - (void)refreshCellModel:(JXCategoryBaseCellModel *)cellModel index:(NSInteger)index {
51 | [super refreshCellModel:cellModel index:index];
52 |
53 | JXCategoryTitleImageCellModel *myCellModel = (JXCategoryTitleImageCellModel *)cellModel;
54 | myCellModel.loadImageCallback = self.loadImageCallback;
55 | myCellModel.imageType = [self.imageTypes[index] integerValue];
56 | myCellModel.imageSize = self.imageSize;
57 | myCellModel.titleImageSpacing = self.titleImageSpacing;
58 | if (self.imageNames != nil) {
59 | myCellModel.imageName = self.imageNames[index];
60 | }else if (self.imageURLs != nil) {
61 | myCellModel.imageURL = self.imageURLs[index];
62 | }
63 | if (self.selectedImageNames != nil) {
64 | myCellModel.selectedImageName = self.selectedImageNames[index];
65 | }else if (self.selectedImageURLs != nil) {
66 | myCellModel.selectedImageURL = self.selectedImageURLs[index];
67 | }
68 | myCellModel.imageZoomEnabled = self.imageZoomEnabled;
69 | myCellModel.imageZoomScale = 1.0;
70 | if (index == self.selectedIndex) {
71 | myCellModel.imageZoomScale = self.imageZoomScale;
72 | }
73 | }
74 |
75 | - (void)refreshSelectedCellModel:(JXCategoryBaseCellModel *)selectedCellModel unselectedCellModel:(JXCategoryBaseCellModel *)unselectedCellModel {
76 | [super refreshSelectedCellModel:selectedCellModel unselectedCellModel:unselectedCellModel];
77 |
78 | JXCategoryTitleImageCellModel *myUnselectedCellModel = (JXCategoryTitleImageCellModel *)unselectedCellModel;
79 | myUnselectedCellModel.imageZoomScale = 1.0;
80 |
81 | JXCategoryTitleImageCellModel *myselectedCellModel = (JXCategoryTitleImageCellModel *)selectedCellModel;
82 | myselectedCellModel.imageZoomScale = self.imageZoomScale;
83 | }
84 |
85 | - (void)refreshLeftCellModel:(JXCategoryBaseCellModel *)leftCellModel rightCellModel:(JXCategoryBaseCellModel *)rightCellModel ratio:(CGFloat)ratio {
86 | [super refreshLeftCellModel:leftCellModel rightCellModel:rightCellModel ratio:ratio];
87 |
88 | JXCategoryTitleImageCellModel *leftModel = (JXCategoryTitleImageCellModel *)leftCellModel;
89 | JXCategoryTitleImageCellModel *rightModel = (JXCategoryTitleImageCellModel *)rightCellModel;
90 |
91 | if (self.imageZoomEnabled) {
92 | leftModel.imageZoomScale = [JXCategoryFactory interpolationFrom:self.imageZoomScale to:1.0 percent:ratio];
93 | rightModel.imageZoomScale = [JXCategoryFactory interpolationFrom:1.0 to:self.imageZoomScale percent:ratio];
94 | }
95 | }
96 |
97 | - (CGFloat)preferredCellWidthAtIndex:(NSInteger)index {
98 | CGFloat titleWidth = [super preferredCellWidthAtIndex:index];
99 | JXCategoryTitleImageType type = [self.imageTypes[index] integerValue];
100 | CGFloat cellWidth = 0;
101 | switch (type) {
102 | case JXCategoryTitleImageType_OnlyTitle:
103 | cellWidth = titleWidth;
104 | break;
105 | case JXCategoryTitleImageType_OnlyImage:
106 | cellWidth = self.imageSize.width;
107 | break;
108 | case JXCategoryTitleImageType_LeftImage:
109 | case JXCategoryTitleImageType_RightImage:
110 | cellWidth = titleWidth + self.titleImageSpacing + self.imageSize.width;
111 | break;
112 | case JXCategoryTitleImageType_TopImage:
113 | case JXCategoryTitleImageType_BottomImage:
114 | cellWidth = MAX(titleWidth, self.imageSize.width);
115 | break;
116 | }
117 | return cellWidth;
118 | }
119 |
120 | @end
121 |
--------------------------------------------------------------------------------
/JXPageListView/PageListView/JXPageListContainerView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXPagingListContainerView.h
3 | // JXPagingView
4 | //
5 | // Created by jiaxin on 2018/8/27.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class JXPageListMainTableView;
12 | @class JXPageListContainerView;
13 |
14 | @protocol JXPageListContainerViewDelegate
15 |
16 | - (NSInteger)numberOfRowsInListContainerView:(JXPageListContainerView *)listContainerView;
17 |
18 | - (UIView *)listContainerView:(JXPageListContainerView *)listContainerView listViewInRow:(NSInteger)row;
19 |
20 | - (void)listContainerView:(JXPageListContainerView *)listContainerView willDisplayCellAtRow:(NSInteger)row;
21 |
22 | @end
23 |
24 |
25 | @interface JXPageListContainerView : UIView
26 |
27 | @property (nonatomic, strong, readonly) UICollectionView *collectionView;
28 | @property (nonatomic, weak) id delegate;
29 | @property (nonatomic, weak) JXPageListMainTableView *mainTableView;
30 |
31 | - (instancetype)initWithDelegate:(id)delegate NS_DESIGNATED_INITIALIZER;
32 |
33 | - (instancetype)init NS_UNAVAILABLE;
34 |
35 | - (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
36 |
37 | - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;
38 |
39 | - (void)reloadData;
40 |
41 | @end
42 |
--------------------------------------------------------------------------------
/JXPageListView/PageListView/JXPageListContainerView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXPagerListContainerView.m
3 | //
4 | // Created by jiaxin on 2018/8/27.
5 | // Copyright © 2018年 jiaxin. All rights reserved.
6 | //
7 |
8 | #import "JXPageListContainerView.h"
9 | #import "JXPageListMainTableView.h"
10 |
11 | @interface JXPageListContainerView()
12 | @property (nonatomic, strong) UICollectionView *collectionView;
13 | @end
14 |
15 | @implementation JXPageListContainerView
16 |
17 | - (instancetype)initWithDelegate:(id)delegate {
18 | self = [super initWithFrame:CGRectZero];
19 | if (self) {
20 | _delegate = delegate;
21 | [self initializeViews];
22 | }
23 | return self;
24 | }
25 |
26 | - (void)initializeViews {
27 | UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
28 | layout.minimumLineSpacing = 0;
29 | layout.minimumInteritemSpacing = 0;
30 | layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
31 |
32 | _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
33 | self.collectionView.showsHorizontalScrollIndicator = NO;
34 | self.collectionView.showsVerticalScrollIndicator = NO;
35 | self.collectionView.pagingEnabled = YES;
36 | self.collectionView.bounces = NO;
37 | self.collectionView.delegate = self;
38 | self.collectionView.dataSource = self;
39 | [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
40 | [self addSubview:self.collectionView];
41 | }
42 |
43 | - (void)layoutSubviews {
44 | [super layoutSubviews];
45 |
46 | self.collectionView.frame = self.bounds;
47 | }
48 |
49 | - (void)reloadData {
50 | [self.collectionView reloadData];
51 | }
52 |
53 | #pragma mark - UICollectionViewDataSource, UICollectionViewDelegate
54 |
55 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
56 | return [self.delegate numberOfRowsInListContainerView:self];
57 | }
58 |
59 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
60 | UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
61 | for (UIView *view in cell.contentView.subviews) {
62 | [view removeFromSuperview];
63 | }
64 | UIView *listView = [self.delegate listContainerView:self listViewInRow:indexPath.item];
65 | listView.frame = cell.contentView.bounds;
66 | [cell.contentView addSubview:listView];
67 | return cell;
68 | }
69 |
70 | - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
71 | [self.delegate listContainerView:self willDisplayCellAtRow:indexPath.item];
72 | }
73 |
74 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
75 | self.mainTableView.scrollEnabled = YES;
76 | }
77 |
78 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
79 | self.mainTableView.scrollEnabled = YES;
80 | }
81 |
82 | - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
83 | self.mainTableView.scrollEnabled = YES;
84 | }
85 |
86 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
87 | if (scrollView.isTracking || scrollView.isDecelerating) {
88 | self.mainTableView.scrollEnabled = NO;
89 | }
90 | }
91 |
92 | #pragma mark - UICollectionViewDelegateFlowLayout
93 |
94 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
95 | return self.bounds.size;
96 | }
97 |
98 | @end
99 |
--------------------------------------------------------------------------------
/JXPageListView/PageListView/JXPageListMainTableView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXPagingMainTableView.h
3 | // JXPagingView
4 | //
5 | // Created by jiaxin on 2018/8/27.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @protocol JXPageListMainTableViewGestureDelegate
12 |
13 | - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
14 |
15 | @end
16 |
17 | @interface JXPageListMainTableView : UITableView
18 | @property (nonatomic, weak) id gestureDelegate;
19 | @end
20 |
--------------------------------------------------------------------------------
/JXPageListView/PageListView/JXPageListMainTableView.m:
--------------------------------------------------------------------------------
1 | //
2 | // JXPagerMainTableView.m
3 | //
4 | // Created by jiaxin on 2018/8/27.
5 | // Copyright © 2018年 jiaxin. All rights reserved.
6 | //
7 |
8 | #import "JXPageListMainTableView.h"
9 |
10 | @interface JXPageListMainTableView ()
11 |
12 | @end
13 |
14 | @implementation JXPageListMainTableView
15 |
16 | - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
17 | if (self.gestureDelegate && [self.gestureDelegate respondsToSelector:@selector(mainTableViewGestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)]) {
18 | return [self.gestureDelegate mainTableViewGestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer];
19 | }else {
20 | return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
21 | }
22 | }
23 |
24 | @end
25 |
--------------------------------------------------------------------------------
/JXPageListView/PageListView/JXPageListView.h:
--------------------------------------------------------------------------------
1 | //
2 | // JXPageView.h
3 | //
4 | // Created by jiaxin on 2018/9/13.
5 | // Copyright © 2018年 jiaxin. All rights reserved.
6 | //
7 |
8 | #import
9 | #import "JXPageListMainTableView.h"
10 | #import "JXPageListContainerView.h"
11 | #import "JXCategoryView.h"
12 |
13 | @class JXPageListView;
14 |
15 | @protocol JXPageListViewListDelegate
16 |
17 |
18 | /**
19 | 返回listView内部持有的UIScrollView或UITableView或UICollectionView
20 | 主要用于mainTableView已经显示了顶部内容,listView的contentOffset需要重置时,内部需要访问到外部传入进来的listView内的scrollView
21 |
22 | @return listView内部持有的UIScrollView或UITableView或UICollectionView
23 | */
24 | - (UIScrollView *)listScrollView;
25 |
26 |
27 | /**
28 | 当listView内部持有的UIScrollView或UITableView或UICollectionView的代理方法`scrollViewDidScroll`回调时,需要调用该代理方法传入的callback
29 |
30 | @param callback `scrollViewDidScroll`回调时调用的callback
31 | */
32 | - (void)listViewDidScrollCallback:(void (^)(UIScrollView *scrollView))callback;
33 |
34 | /**
35 | 选中listView之后触发数据加载。会多次回调,所以listView内部要做个标志,第一次才触发数据加载。
36 | */
37 | - (void)listViewLoadDataIfNeeded;
38 |
39 | @end
40 |
41 | @protocol JXPageListViewDelegate
42 |
43 | /**
44 | 返回listViews,数组的item需要是UIView的子类,且要遵循JXPageListViewListDelegate。
45 | 数组item要求返回一个UIView而不是一个UIScrollView,因为列表的UIScrollView一般是被包装到一个view里面,里面会处理数据源和其他逻辑。
46 |
47 | @param pageListView pageListView description
48 | @return listViews
49 | */
50 | - (NSArray *>*)listViewsInPageListView:(JXPageListView *)pageListView;
51 |
52 | @optional
53 |
54 | /**
55 | 悬浮分类视图选中某个index的回调
56 |
57 | @param pinCategoryView 悬浮分类视图
58 | @param index index
59 | */
60 | - (void)pinCategoryView:(JXCategoryBaseView *)pinCategoryView didSelectedItemAtIndex:(NSInteger)index;
61 |
62 | @end
63 |
64 |
65 | /**
66 | 按照demo工程PageViewController里面的tips使用,把最后一个section留给listContainerCell。其余的,你就把mainTableView当做普通的tableView来处理就行。上面想添加多少cell都随你。
67 | */
68 | @interface JXPageListView : UIView
69 |
70 | @property (nonatomic, strong, readonly) JXCategoryTitleView *pinCategoryView;
71 |
72 | @property (nonatomic, strong, readonly) JXPageListMainTableView *mainTableView;
73 |
74 | @property (nonatomic, assign, getter=isListViewScrollStateSaveEnabled) BOOL listViewScrollStateSaveEnabled; //是否保存底部滚动列表视图的滚动状态,默认YES。设置为YES,表示A列表被滚动一定距离后,切换到B列表,当B列表往上滚动到最顶部的时候,再切换到A列表,A列表保存了它之前的滚动距离;设置为NO,表示A列表被滚动一定距离后,切换到B列表,当B列表往上滚动到最顶部的时候,再切换到A列表,A列表也同步被滚动到最顶部了;具体可以参考demo效果。
75 |
76 | @property (nonatomic, assign) CGFloat pinCategoryViewHeight; //顶部固定悬浮categoryView的高度
77 |
78 | @property (nonatomic, assign) CGFloat pinCategoryViewVerticalOffset; //顶部固定sectionHeader的垂直偏移量。数值越大越往下沉。
79 |
80 | - (instancetype)initWithDelegate:(id)delegate NS_DESIGNATED_INITIALIZER;
81 |
82 | - (instancetype)init NS_UNAVAILABLE;
83 |
84 | - (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
85 |
86 | - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;
87 |
88 | /**
89 | 通过服务器获取到数据之后,再调用reloadData方法刷新
90 | */
91 | - (void)reloadData;
92 |
93 | /**
94 | 返回列表容器cell的高度
95 | */
96 | - (CGFloat)listContainerCellHeight;
97 |
98 | /**
99 | 返回列表容器cell
100 | */
101 | - (UITableViewCell *)listContainerCellForRowAtIndexPath:(NSIndexPath *)indexPath;
102 |
103 | /**
104 | mainTableView的代理方法`scrollViewDidScroll`回调时需要调用该方法
105 | */
106 | - (void)mainTableViewDidScroll:(UIScrollView *)scrollView;
107 |
108 | @end
109 |
--------------------------------------------------------------------------------
/JXPageListView/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/14.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UITableViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/JXPageListView/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/14.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "PageViewController.h"
11 | #import "NormalViewController.h"
12 |
13 | @interface ViewController ()
14 |
15 | @end
16 |
17 | @implementation ViewController
18 |
19 | - (void)viewDidLoad {
20 | [super viewDidLoad];
21 | // Do any additional setup after loading the view, typically from a nib.
22 | }
23 |
24 |
25 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
26 | switch (indexPath.row) {
27 | case 0:
28 | {
29 | NormalViewController *vc = [[NormalViewController alloc] init];
30 | [self.navigationController pushViewController:vc animated:YES];
31 | }
32 | break;
33 | case 1:
34 | {
35 | PageViewController *vc = [[PageViewController alloc] init];
36 | vc.isNeedHeader = YES;
37 | vc.listViewScrollStateSaveEnabled = YES;
38 | [self.navigationController pushViewController:vc animated:YES];
39 | }
40 | break;
41 | case 2:
42 | {
43 | PageViewController *vc = [[PageViewController alloc] init];
44 | vc.listViewScrollStateSaveEnabled = YES;
45 | [self.navigationController pushViewController:vc animated:YES];
46 | }
47 | break;
48 | case 3:
49 | {
50 | PageViewController *vc = [[PageViewController alloc] init];
51 | vc.listViewScrollStateSaveEnabled = NO;
52 | [self.navigationController pushViewController:vc animated:YES];
53 | }
54 | break;
55 | case 4:
56 | {
57 | PageViewController *vc = [[PageViewController alloc] init];
58 | vc.listViewScrollStateSaveEnabled = YES;
59 | vc.pinCategoryViewVerticalOffset = 100;
60 | [self.navigationController pushViewController:vc animated:YES];
61 | }
62 | break;
63 | case 5:
64 | {
65 | PageViewController *vc = [[PageViewController alloc] init];
66 | vc.isNeedScrollToBottom = YES;
67 | [self.navigationController pushViewController:vc animated:YES];
68 | }
69 | break;
70 | default:
71 | break;
72 | }
73 | }
74 |
75 | @end
76 |
--------------------------------------------------------------------------------
/JXPageListView/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // JXPageListView
4 | //
5 | // Created by jiaxin on 2018/9/14.
6 | // Copyright © 2018年 jiaxin. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 暴走的鑫鑫
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JXPageListView
2 | 高仿闲鱼、转转、京东、中央天气预报等主流APP列表底部分页滚动视图
3 |
4 | # 特性
5 |
6 | - 上下左右滚动交互流畅;
7 | - 支持MJRefresh等header加载;
8 | - 支持HUD loading加载;
9 | - 支持底部分类滚动列表状态保存;
10 | - 支持底部分类滚动列表状态不保存;
11 |
12 | # 效果预览
13 |
14 | | 说明 | GIF|
15 | |------|------|
16 | | 上下左右交互 | |
17 | | MJRefresh刷新加载 |  |
18 | | HUD loading加载 | 
19 | | 保存底部列表滚动状态 |  |
20 | | 不保存底部列表滚动状态 |  |
21 | | **JXPagingView**
如果只需要HeaderView
请点击查看该库[JXPagingView](https://github.com/pujiaxin33/JXPagingView)
请点击查看该库[JXPagingView](https://github.com/pujiaxin33/JXPagingView)
请点击查看该库[JXPagingView](https://github.com/pujiaxin33/JXPagingView) |  |
22 |
23 | # 使用
24 |
25 | - 初始化`pageListView`
26 |
27 | ```Objective-C
28 | self.pageListView = [[JXPageListView alloc] initWithDelegate:self];
29 | ```
30 |
31 | - 配置分类视图`pinCategoryView`
32 |
33 | ```Objective-C
34 | self.pageListView.pinCategoryView.titles = self.titles;
35 | ```
36 |
37 | - 成为mainTableView的代理,像使用普通UITableView一样使用它;
38 | ```Objective-C
39 | self.pageListView.mainTableView.dataSource = self;
40 | self.pageListView.mainTableView.delegate = self;
41 | ```
42 |
43 | - `UITableViewDataSource, UITableViewDelegate`代理方法实现
44 |
45 | ```Objective-C
46 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
47 | return 1 + “你的顶部内容section数量”;//底部的分类滚动视图需要作为最后一个section
48 | }
49 |
50 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
51 | if (section == 2) {
52 | //Tips:最后一个section(即listContainerCell所在的section)需要返回1
53 | return 1;
54 | }
55 | //返回你的顶部内容 row number
56 | }
57 |
58 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
59 | if (indexPath.section == 2) {
60 | //Tips:最后一个section(即listContainerCell所在的section)返回listContainerCell的高度
61 | return [self.pageListView listContainerCellHeight];
62 | }
63 | //返回你的顶部内容 cell height
64 | }
65 |
66 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
67 | if (indexPath.section == 2) {
68 | //Tips:最后一个section(即listContainerCell所在的section)配置listContainerCell
69 | return [self.pageListView listContainerCellForRowAtIndexPath:indexPath];
70 | }
71 | //返回你的顶部内容 cell
72 | }
73 |
74 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
75 | //Tips:需要传入mainTableView的scrollViewDidScroll事件
76 | [self.pageListView mainTableViewDidScroll:scrollView];
77 | }
78 | ```
79 |
80 | - `JXPageViewDelegate`代理方法实现
81 | ```Objective-C
82 | //返回底部的列表视图
83 | - (NSArray *> *)listViewsInPageListView:(JXPageListView *)pageListView {
84 | return self.listViewArray;
85 | }
86 | ```
87 |
88 | # JXPagingView推荐
89 | 如果你只想找一个顶部只有少量视图(类似TableHeaderView的概念),推荐你看我的这个库:[JXPagingView](https://github.com/pujiaxin33/JXPagingView)
90 |
91 | # JXCategoryView推荐
92 | 如果你想要支持所有主流APP分类切换效果的框架,推荐你看我的这个库,目前已经1.4k stars:[JXCategoryView](https://github.com/pujiaxin33/JXCategoryView)
93 |
94 | # 补充
95 | 有任何疑问欢迎通过以下方式联系我:
96 | - 提issue;
97 | - 邮箱:317437087@qq.com
98 | - QQ:317437087
99 |
--------------------------------------------------------------------------------