Browse Source

Add trailer example (#1462)

- add trailer example
Kinarobin 5 years ago
parent
commit
ed5b6d0410

+ 6 - 0
MJRefreshExample.xcodeproj/project.pbxproj

@@ -94,6 +94,7 @@
 		2DB2EA271BECBE6700D58F6A /* UIScrollView+MJExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DB2EA121BECBE6700D58F6A /* UIScrollView+MJExtension.m */; };
 		2DB2EA281BECBE6700D58F6A /* UIScrollView+MJRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DB2EA141BECBE6700D58F6A /* UIScrollView+MJRefresh.m */; };
 		2DB2EA291BECBE6700D58F6A /* UIView+MJExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DB2EA161BECBE6700D58F6A /* UIView+MJExtension.m */; };
+		6B8FB1A9250E610D00AF64B7 /* MJHorizontalCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B8FB1A8250E610D00AF64B7 /* MJHorizontalCollectionViewController.m */; };
 		84FC857E228037CE001C6728 /* MJRefreshConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 01A2CE0B21ACE01500BEE365 /* MJRefreshConfig.m */; };
 		88E3200B24839ABA00069FA7 /* MJRefreshTrailer.m in Sources */ = {isa = PBXBuildFile; fileRef = 88E3200924839ABA00069FA7 /* MJRefreshTrailer.m */; };
 		88E3201124839B2300069FA7 /* MJRefreshStateTrailer.m in Sources */ = {isa = PBXBuildFile; fileRef = 88E3200E24839B2300069FA7 /* MJRefreshStateTrailer.m */; };
@@ -221,6 +222,8 @@
 		2DB2EA141BECBE6700D58F6A /* UIScrollView+MJRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+MJRefresh.m"; sourceTree = "<group>"; };
 		2DB2EA151BECBE6700D58F6A /* UIView+MJExtension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+MJExtension.h"; sourceTree = "<group>"; };
 		2DB2EA161BECBE6700D58F6A /* UIView+MJExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+MJExtension.m"; sourceTree = "<group>"; };
+		6B8FB1A7250E610D00AF64B7 /* MJHorizontalCollectionViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MJHorizontalCollectionViewController.h; sourceTree = "<group>"; };
+		6B8FB1A8250E610D00AF64B7 /* MJHorizontalCollectionViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MJHorizontalCollectionViewController.m; sourceTree = "<group>"; };
 		88E3200924839ABA00069FA7 /* MJRefreshTrailer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshTrailer.m; sourceTree = "<group>"; };
 		88E3200A24839ABA00069FA7 /* MJRefreshTrailer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshTrailer.h; sourceTree = "<group>"; };
 		88E3200D24839B2300069FA7 /* MJRefreshNormalTrailer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJRefreshNormalTrailer.h; sourceTree = "<group>"; };
@@ -315,6 +318,8 @@
 			children = (
 				2D9BEAFF1BB15F4A00AED473 /* MJCollectionViewController.h */,
 				2D9BEB001BB15F4A00AED473 /* MJCollectionViewController.m */,
+				6B8FB1A7250E610D00AF64B7 /* MJHorizontalCollectionViewController.h */,
+				6B8FB1A8250E610D00AF64B7 /* MJHorizontalCollectionViewController.m */,
 				2D9BEB011BB15F4A00AED473 /* MJTableViewController.h */,
 				2D9BEB021BB15F4A00AED473 /* MJTableViewController.m */,
 				2D9BEB031BB15F4A00AED473 /* MJTestViewController.h */,
@@ -745,6 +750,7 @@
 				2DB2EA241BECBE6700D58F6A /* MJRefreshStateHeader.m in Sources */,
 				2D9BEB091BB15F4A00AED473 /* UIViewController+Example.m in Sources */,
 				88E3200B24839ABA00069FA7 /* MJRefreshTrailer.m in Sources */,
+				6B8FB1A9250E610D00AF64B7 /* MJHorizontalCollectionViewController.m in Sources */,
 				2D9BEB111BB15F4A00AED473 /* MJExampleViewController.m in Sources */,
 				88E3201124839B2300069FA7 /* MJRefreshStateTrailer.m in Sources */,
 				2DB2EA1D1BECBE6700D58F6A /* MJRefreshAutoNormalFooter.m in Sources */,

+ 7 - 1
MJRefreshExample/Classes/First/MJExampleViewController.m

@@ -15,6 +15,7 @@
 #import "UIViewController+Example.h"
 #import "MJRefresh.h"
 #import "MJWKWebViewController.h"
+#import "MJHorizontalCollectionViewController.h"
 
 static NSString *const MJExample00 = @"UITableView + 下拉刷新";
 static NSString *const MJExample10 = @"UITableView + 上拉刷新";
@@ -61,8 +62,13 @@ - (NSArray *)examples
         exam4.titles = @[@"下拉刷新"];
         exam4.methods = @[@"example41"];
         
+        MJExample *exam5 = [[MJExample alloc] init];
+        exam5.header = MJExample20;
+        exam5.vcClass = [MJHorizontalCollectionViewController class];
+        exam5.titles = @[@"左拉刷新"];
+        exam5.methods = @[@"example42"];
         
-        self.examples = @[exam0, exam1, exam2, exam3, exam4];
+        self.examples = @[exam0, exam1, exam2, exam3, exam4, exam5];
     }
     return _examples;
 }

+ 17 - 0
MJRefreshExample/Classes/Second/MJHorizontalCollectionViewController.h

@@ -0,0 +1,17 @@
+//
+//  MJHorizontalCollectionViewController.h
+//  MJRefreshExample
+//
+//  Created by libin14 on 2020/9/13.
+//  Copyright © 2020 小码哥. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface MJHorizontalCollectionViewController : UICollectionViewController
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 101 - 0
MJRefreshExample/Classes/Second/MJHorizontalCollectionViewController.m

@@ -0,0 +1,101 @@
+//  代码地址: https://github.com/CoderMJLee/MJRefresh
+//  代码地址: 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
+//  MJHorizontalCollectionViewController.m
+//  MJRefreshExample
+//
+//  Created by MJ Lee on 15/3/6.
+//  Copyright (c) 2015年 小码哥. All rights reserved.
+//
+
+#import "MJHorizontalCollectionViewController.h"
+#import "MJTestViewController.h"
+#import "UIViewController+Example.h"
+#import "MJRefresh.h"
+
+/**
+ * 随机色
+ */
+#define MJRandomColor [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1]
+
+@interface MJHorizontalCollectionViewController()
+/** 存放假数据 */
+@property (strong, nonatomic) NSMutableArray *colors;
+@end
+
+@implementation MJHorizontalCollectionViewController
+#pragma mark - 示例
+#pragma mark UICollectionView 左拉刷新
+
+- (void)example42 {
+    __weak __typeof(self) weakSelf = self;
+    
+    // 左拉刷新
+    self.collectionView.mj_trailer = [MJRefreshNormalTrailer trailerWithRefreshingBlock:^{
+        MJTestViewController *test = [[MJTestViewController alloc] init];
+        [weakSelf.navigationController pushViewController:test animated:YES];
+        [weakSelf.collectionView.mj_trailer endRefreshing];
+    }];
+}
+
+#pragma mark - 数据相关
+- (NSMutableArray *)colors {
+    if (!_colors) {
+        self.colors = [NSMutableArray array];
+        for (int i = 0; i < 5; i++) {
+            [self.colors addObject:MJRandomColor];
+        }
+    }
+    return _colors;
+}
+
+#pragma mark - 其他
+
+/**
+ *  初始化
+ */
+- (instancetype)init {
+    // UICollectionViewFlowLayout的初始化(与刷新控件无关)
+    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
+    layout.itemSize = CGSizeMake(UIScreen.mainScreen.bounds.size.width, 200);
+    layout.minimumInteritemSpacing = 0;
+    layout.minimumLineSpacing = 0;
+    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
+    return [self initWithCollectionViewLayout:layout];
+}
+
+static NSString *const MJCollectionViewCellIdentifier = @"color";
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    
+    self.view.backgroundColor = [UIColor whiteColor];
+    
+    self.collectionView.frame = CGRectMake(0, 150, UIScreen.mainScreen.bounds.size.width, 200);
+    self.collectionView.pagingEnabled = YES;
+    self.collectionView.backgroundColor = [UIColor whiteColor];
+    
+    MJPerformSelectorLeakWarning([self performSelector:NSSelectorFromString(self.method) withObject:nil];);
+    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:MJCollectionViewCellIdentifier];
+}
+
+#pragma mark - collection数据源代理
+- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
+    return self.colors.count;
+}
+
+- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
+    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MJCollectionViewCellIdentifier forIndexPath:indexPath];
+    cell.backgroundColor = self.colors[indexPath.row];
+    return cell;
+}
+
+- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
+    MJTestViewController *test = [[MJTestViewController alloc] init];
+    if (indexPath.row % 2) {
+        [self.navigationController pushViewController:test animated:YES];
+    } else {
+        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:test];
+        [self presentViewController:nav animated:YES completion:nil];
+    }
+}
+@end

+ 1 - 1
MJRefreshExample/Classes/Second/MJTableViewController.m

@@ -21,7 +21,7 @@
 #import "MJDIYAutoFooter.h"
 #import "MJDIYBackFooter.h"
 
-static const CGFloat MJDuration = 2.0;
+static const CGFloat MJDuration = 0.5;
 /**
  * 随机数据
  */

+ 26 - 0
README.md

@@ -17,6 +17,7 @@
 	* [MJRefreshHeader.h](#MJRefreshHeader.h)
 	* [MJRefreshFooter.h](#MJRefreshFooter.h)
 	* [MJRefreshAutoFooter.h](#MJRefreshAutoFooter.h)
+	* [MJRefreshTrailer.h](#MJRefreshTrailer.h)
 * Examples
     * [Reference](#Reference)
     * [The drop-down refresh 01-Default](#The_drop-down_refresh_01-Default)
@@ -36,6 +37,7 @@
     * [The pull to refresh 09-DIY the control of refresh(Automatic refresh)](#The_pull_to_refresh_09-DIY_the_control_of_refresh(Automatic_refresh))
     * [The pull to refresh 10-DIY the control of refresh(Automatic back)](#The_pull_to_refresh_10-DIY_the_control_of_refresh(Automatic_back))
     * [UICollectionView01-The pull and drop-down refresh](#UICollectionView01-The_pull_and_drop-down_refresh)
+    * [UICollectionView02-The trailer refresh](#UICollectionView02-The_trailer_refresh)
     * [WKWebView01-The drop-down refresh](#WKWebView01-The_drop-down_refresh)
 * [Hope](#Hope)
 
@@ -145,6 +147,21 @@ UIView+MJExtension.h        UIView+MJExtension.m
 @end
 ```
 
+## <a id="MJRefreshTrailer.h"></a> MJRefreshTrailer.h
+```objc
+@interface MJRefreshTrailer : MJRefreshComponent
+
+/** 创建trailer */
++ (instancetype)trailerWithRefreshingBlock:(MJRefreshComponentAction)refreshingBlock;
+/** 创建trailer */
++ (instancetype)trailerWithRefreshingTarget:(id)target refreshingAction:(SEL)action;
+
+/** 忽略多少scrollView的contentInset的right */
+@property (assign, nonatomic) CGFloat ignoredScrollViewContentInsetRight;
+
+@end
+```
+
 ## <a id="Reference"></a>Reference
 ```objc
 * Due to there are more functions of this framework,Don't write specific text describe its usage
@@ -334,6 +351,15 @@ self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingB
 ```
 ![(UICollectionView01-上下拉刷新)](http://images0.cnblogs.com/blog2015/497279/201506/141206021603758.gif)
 
+## <a id="UICollectionView02-The_trailer_refresh"></a>UICollectionView02-The trailer refresh
+```objc
+// The trailer refresh
+self.collectionView.mj_trailer = [MJRefreshNormalTrailer trailerWithRefreshingBlock:^{
+   //Call this Block When enter the refresh status automatically 
+}];
+
+```
+
 ## <a id="WKWebView01-The_drop-down_refresh"></a>WKWebView01-The drop-down refresh
 ```objc
 //Add the control of The drop-down refresh