Selaa lähdekoodia

Back footer position

Back footer position
MJLee 10 vuotta sitten
vanhempi
commit
1cfebd7595

+ 37 - 11
MJRefresh.podspec

@@ -1,13 +1,39 @@
 Pod::Spec.new do |s|
-  s.name         = "MJRefresh"
-  s.version      = "2.4.7"
-  s.summary      = "The easiest way to use pull-to-refresh"
-  s.homepage     = "https://github.com/CoderMJLee/MJRefresh"
-  s.license      = "MIT"
-  s.authors      = { 'MJ Lee' => '199109106@qq.com'}
-  s.platform     = :ios, "6.0"
-  s.source       = { :git => "https://github.com/CoderMJLee/MJRefresh.git", :tag => s.version }
-  s.source_files = "MJRefresh/**/*.{h,m}"
-  s.resource     = "MJRefresh/MJRefresh.bundle"
-  s.requires_arc = true
+    s.name         = "MJRefresh"
+    s.version      = "2.4.8"
+    s.summary      = "The easiest way to use pull-to-refresh"
+    s.homepage     = "https://github.com/CoderMJLee/MJRefresh"
+    s.license      = "MIT"
+    s.authors      = { 'MJ Lee' => '199109106@qq.com'}
+    s.platform     = :ios, "6.0"
+    s.source       = { :git => "https://github.com/CoderMJLee/MJRefresh.git", :tag => s.version }
+    s.source_files = "MJRefresh/*.{h,m}"
+    s.resource     = "MJRefresh/MJRefresh.bundle"
+    s.requires_arc = true
+
+    s.subspec 'Base' do |Base|
+        Base.source_files = 'MJRefresh/Base/*.{h,m}'
+    end
+
+    s.subspec 'Custom' do |Custom|
+        Custom.subspec 'Footer' do |Footer|
+            Footer.subspec 'Auto' do |Auto|
+                Auto.source_files = "MJRefresh/Custom/Footer/Auto/*.{h,m}"
+            end
+
+            Footer.subspec 'Back' do |Back|
+                Back.source_files = "MJRefresh/Custom/Footer/Back/*.{h,m}"
+            end
+        end
+
+        Custom.subspec 'Header' do |Header|
+            Header.subspec 'Auto' do |Auto|
+                Auto.source_files = "MJRefresh/Custom/Header/Auto/*.{h,m}"
+            end
+
+            Header.subspec 'Back' do |Back|
+                Back.source_files = "MJRefresh/Custom/Header/Back/*.{h,m}"
+            end
+        end
+    end
 end

+ 4 - 1
MJRefresh/Base/MJRefreshAutoFooter.h

@@ -13,5 +13,8 @@
 @property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh;
 
 /** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */
-@property (assign, nonatomic) CGFloat appearencePercentTriggerAutoRefresh;
+@property (assign, nonatomic) CGFloat appearencePercentTriggerAutoRefresh MJRefreshDeprecated("请使用automaticallyChangeAlpha属性");
+
+/** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */
+@property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent;
 @end

+ 14 - 3
MJRefresh/Base/MJRefreshAutoFooter.m

@@ -32,13 +32,24 @@ - (void)willMoveToSuperview:(UIView *)newSuperview
     }
 }
 
+#pragma mark - 过期方法
+- (void)setAppearencePercentTriggerAutoRefresh:(CGFloat)appearencePercentTriggerAutoRefresh
+{
+    self.triggerAutomaticallyRefreshPercent = appearencePercentTriggerAutoRefresh;
+}
+
+- (CGFloat)appearencePercentTriggerAutoRefresh
+{
+    return self.triggerAutomaticallyRefreshPercent;
+}
+
 #pragma mark - 实现父类的方法
 - (void)prepare
 {
     [super prepare];
     
     // 默认底部控件100%出现时才会自动刷新
-    self.appearencePercentTriggerAutoRefresh = 1.0;
+    self.triggerAutomaticallyRefreshPercent = 1.0;
     
     // 设置为默认状态
     self.automaticallyRefresh = YES;
@@ -49,7 +60,7 @@ - (void)scrollViewContentSizeDidChange:(NSDictionary *)change
     [super scrollViewContentSizeDidChange:change];
     
     // 设置位置
-    self.mj_y = _scrollView.mj_contentH;
+    self.mj_y = self.scrollView.mj_contentH;
 }
 
 - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
@@ -60,7 +71,7 @@ - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
     
     if (_scrollView.mj_insetT + _scrollView.mj_contentH > _scrollView.mj_h) { // 内容超过一个屏幕
         // 这里的_scrollView.mj_contentH替换掉self.mj_y更为合理
-        if (_scrollView.mj_offsetY >= _scrollView.mj_contentH - _scrollView.mj_h + self.mj_h * self.appearencePercentTriggerAutoRefresh + _scrollView.mj_insetB - self.mj_h) {
+        if (_scrollView.mj_offsetY >= _scrollView.mj_contentH - _scrollView.mj_h + self.mj_h * self.triggerAutomaticallyRefreshPercent + _scrollView.mj_insetB - self.mj_h) {
             // 防止手松开时连续调用
             CGPoint old = [change[@"old"] CGPointValue];
             CGPoint new = [change[@"new"] CGPointValue];

+ 8 - 1
MJRefresh/Base/MJRefreshBackFooter.m

@@ -15,6 +15,14 @@ @interface MJRefreshBackFooter()
 
 @implementation MJRefreshBackFooter
 
+#pragma mark - 初始化
+- (void)willMoveToSuperview:(UIView *)newSuperview
+{
+    [super willMoveToSuperview:newSuperview];
+    
+    [self scrollViewContentSizeDidChange:nil];
+}
+
 #pragma mark - 实现父类的方法
 - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
 {
@@ -68,7 +76,6 @@ - (void)scrollViewContentSizeDidChange:(NSDictionary *)change
     CGFloat contentHeight = self.scrollView.mj_contentH + self.ignoredScrollViewContentInsetBottom;
     // 表格的高度
     CGFloat scrollHeight = self.scrollView.mj_h - self.scrollViewOriginalInset.top - self.scrollViewOriginalInset.bottom + self.ignoredScrollViewContentInsetBottom;
-    // 这里一定是用:self.scrollView.mj_insetT 和 self.scrollViewOriginalInset.bottom;
     // 设置位置和尺寸
     self.mj_y = MAX(contentHeight, scrollHeight);
 }

+ 1 - 0
MJRefresh/Base/MJRefreshComponent.h

@@ -78,6 +78,7 @@ typedef void (^MJRefreshComponentRefreshingBlock)();
 /** 当scrollView的拖拽状态发生改变的时候调用 */
 - (void)scrollViewPanStateDidChange:(NSDictionary *)change;
 
+
 #pragma mark - 其他
 /** 拉拽的百分比(交给子类重写) */
 @property (assign, nonatomic) CGFloat pullingPercent;

+ 7 - 2
MJRefresh/Base/MJRefreshComponent.m

@@ -10,6 +10,7 @@
 #import "MJRefreshComponent.h"
 #import "MJRefreshConst.h"
 #import "UIView+MJExtension.h"
+#import "UIScrollView+MJRefresh.h"
 
 @interface MJRefreshComponent()
 @property (strong, nonatomic) UIPanGestureRecognizer *pan;
@@ -66,7 +67,7 @@ - (void)willMoveToSuperview:(UIView *)newSuperview
         // 设置永远支持垂直弹簧效果
         _scrollView.alwaysBounceVertical = YES;
         // 记录UIScrollView最开始的contentInset
-        _scrollViewOriginalInset = self.scrollView.contentInset;
+        _scrollViewOriginalInset = _scrollView.contentInset;
         
         // 添加监听
         [self addObservers];
@@ -167,11 +168,15 @@ - (void)setAutoChangeAlpha:(BOOL)autoChangeAlpha
     self.automaticallyChangeAlpha = autoChangeAlpha;
 }
 
+- (BOOL)isAutoChangeAlpha
+{
+    return self.isAutomaticallyChangeAlpha;
+}
+
 - (void)setAutomaticallyChangeAlpha:(BOOL)automaticallyChangeAlpha
 {
     _automaticallyChangeAlpha = automaticallyChangeAlpha;
     
-    
     if (self.isRefreshing) return;
     
     if (automaticallyChangeAlpha) {

+ 1 - 0
MJRefresh/Base/MJRefreshHeader.m

@@ -72,6 +72,7 @@ - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
     // 普通 和 即将刷新 的临界点
     CGFloat normal2pullingOffsetY = happenOffsetY - self.mj_h;
     CGFloat pullingPercent = (happenOffsetY - offsetY) / self.mj_h;
+    
     if (self.scrollView.isDragging) { // 如果正在拖拽
         self.pullingPercent = pullingPercent;
         if (self.state == MJRefreshStateIdle && offsetY < normal2pullingOffsetY) {

+ 1 - 2
MJRefresh/UIScrollView+MJRefresh.m

@@ -107,8 +107,7 @@ - (void)setReloadDataBlock:(void (^)(NSInteger))reloadDataBlock
 
 - (void)executeReloadDataBlock
 {
-    void (^reloadDataBlock)(NSInteger) = self.reloadDataBlock;
-    !reloadDataBlock ? : reloadDataBlock(self.totalDataCount);
+    !self.reloadDataBlock ? : self.reloadDataBlock(self.totalDataCount);
 }
 @end
 

+ 6 - 0
MJRefreshExample/MJRefreshExample.xcodeproj/project.pbxproj

@@ -8,6 +8,7 @@
 
 /* Begin PBXBuildFile section */
 		2D30C3B21B2BE95E00A207DF /* MJTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2D30C3B11B2BE95E00A207DF /* MJTableViewCell.xib */; };
+		2D415E6E1B81ECC30068038E /* MJExampleWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D415E6D1B81ECC30068038E /* MJExampleWindow.m */; };
 		2D4A99A71AB1727900828496 /* MJWebViewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D4A99A51AB1727900828496 /* MJWebViewViewController.m */; };
 		2D4A99A81AB1727900828496 /* MJWebViewViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2D4A99A61AB1727900828496 /* MJWebViewViewController.xib */; };
 		2D4A99AB1AB178EB00828496 /* UIViewController+Example.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D4A99AA1AB178EB00828496 /* UIViewController+Example.m */; };
@@ -64,6 +65,8 @@
 
 /* Begin PBXFileReference section */
 		2D30C3B11B2BE95E00A207DF /* MJTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MJTableViewCell.xib; sourceTree = "<group>"; };
+		2D415E6C1B81ECC30068038E /* MJExampleWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJExampleWindow.h; sourceTree = "<group>"; };
+		2D415E6D1B81ECC30068038E /* MJExampleWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJExampleWindow.m; sourceTree = "<group>"; };
 		2D4A99A41AB1727900828496 /* MJWebViewViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MJWebViewViewController.h; sourceTree = "<group>"; };
 		2D4A99A51AB1727900828496 /* MJWebViewViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJWebViewViewController.m; sourceTree = "<group>"; };
 		2D4A99A61AB1727900828496 /* MJWebViewViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MJWebViewViewController.xib; sourceTree = "<group>"; };
@@ -339,6 +342,8 @@
 				2DA7F9501AA6B51C005627AB /* AppDelegate.m */,
 				2D4A99A91AB178EB00828496 /* UIViewController+Example.h */,
 				2D4A99AA1AB178EB00828496 /* UIViewController+Example.m */,
+				2D415E6C1B81ECC30068038E /* MJExampleWindow.h */,
+				2D415E6D1B81ECC30068038E /* MJExampleWindow.m */,
 			);
 			name = Other;
 			sourceTree = "<group>";
@@ -490,6 +495,7 @@
 				2D77810C1B2C1E19009EF21B /* MJRefreshComponent.m in Sources */,
 				2D7780F91B2C1DE4009EF21B /* MJRefreshConst.m in Sources */,
 				2D4A99A71AB1727900828496 /* MJWebViewViewController.m in Sources */,
+				2D415E6E1B81ECC30068038E /* MJExampleWindow.m in Sources */,
 				2D7780EF1B2C1DE4009EF21B /* MJRefreshBackGifFooter.m in Sources */,
 				2D77810B1B2C1E19009EF21B /* MJRefreshBackFooter.m in Sources */,
 				2D7780EC1B2C1DE4009EF21B /* MJRefreshAutoGifFooter.m in Sources */,

BIN
MJRefreshExample/MJRefreshExample.xcodeproj/project.xcworkspace/xcuserdata/mj.xcuserdatad/UserInterfaceState.xcuserstate


+ 1 - 1
MJRefreshExample/MJRefreshExample/Base.lproj/Main.storyboard

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7703" systemVersion="14F25a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="06B-cM-i4B">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7703" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="06B-cM-i4B">
     <dependencies>
         <deployment identifier="iOS"/>
         <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6711"/>

+ 2 - 20
MJRefreshExample/MJRefreshExample/Classes/AppDelegate.m

@@ -8,9 +8,9 @@
 //
 
 #import "AppDelegate.h"
+#import "MJExampleWindow.h"
 
 @interface AppDelegate ()
-@property (strong, nonatomic) UIWindow *alert;
 @end
 
 @implementation AppDelegate
@@ -20,11 +20,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
     return YES;
 }
 
-- (void)contorlSelect:(UISegmentedControl *)control
-{
-    self.window.rootViewController = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%zd", control.selectedSegmentIndex]];
-}
-
 - (void)applicationWillResignActive:(UIApplication *)application {
     // 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.
     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
@@ -43,20 +38,7 @@ - (void)applicationDidBecomeActive:(UIApplication *)application {
     // 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.
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
-        UIWindow *alert = [[UIWindow alloc] init];
-        CGFloat width = 150;
-        CGFloat x = [UIScreen mainScreen].bounds.size.width - width - 10;
-        alert.frame = CGRectMake(x, 0, width, 25);
-        alert.windowLevel = UIWindowLevelAlert;
-        alert.hidden = NO;
-        alert.alpha = 0.5;
-        UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:@[@"示例1", @"示例2", @"示例3"]];
-        control.tintColor = [UIColor orangeColor];
-        control.frame = alert.bounds;
-        control.selectedSegmentIndex = 0;
-        [control addTarget:self action:@selector(contorlSelect:) forControlEvents:UIControlEventValueChanged];
-        [alert addSubview:control];
-        self.alert = alert;
+        [MJExampleWindow show];
     });
 }
 

+ 13 - 0
MJRefreshExample/MJRefreshExample/Classes/MJExampleWindow.h

@@ -0,0 +1,13 @@
+//
+//  MJExampleWindow.h
+//  MJRefreshExample
+//
+//  Created by MJ Lee on 15/8/17.
+//  Copyright (c) 2015年 小码哥. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface MJExampleWindow : UIWindow
++ (void)show;
+@end

+ 37 - 0
MJRefreshExample/MJRefreshExample/Classes/MJExampleWindow.m

@@ -0,0 +1,37 @@
+//
+//  MJExampleWindow.m
+//  MJRefreshExample
+//
+//  Created by MJ Lee on 15/8/17.
+//  Copyright (c) 2015年 小码哥. All rights reserved.
+//
+
+#import "MJExampleWindow.h"
+
+@implementation MJExampleWindow
+
+static UIWindow *window_;
++ (void)show
+{
+    window_ = [[UIWindow alloc] init];
+    CGFloat width = 150;
+    CGFloat x = [UIScreen mainScreen].bounds.size.width - width - 10;
+    window_.frame = CGRectMake(x, 0, width, 25);
+    window_.windowLevel = UIWindowLevelAlert;
+    window_.hidden = NO;
+    window_.alpha = 0.5;
+    
+    UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:@[@"示例1", @"示例2", @"示例3"]];
+    control.tintColor = [UIColor orangeColor];
+    control.frame = window_.bounds;
+    control.selectedSegmentIndex = 0;
+    [control addTarget:self action:@selector(contorlSelect:) forControlEvents:UIControlEventValueChanged];
+    [window_ addSubview:control];
+}
+
++ (void)contorlSelect:(UISegmentedControl *)control
+{
+    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
+    keyWindow.rootViewController = [keyWindow.rootViewController.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%zd", control.selectedSegmentIndex]];
+}
+@end

+ 0 - 1
MJRefreshExample/MJRefreshExample/Classes/MJSingleViewController.m

@@ -42,7 +42,6 @@ - (void)viewDidLoad {
     }];
     footer.hidden = YES;
     tableView.footer = footer;
-//    tableView.footer.automaticallyChangeAlpha = YES;
 }
 
 - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section

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

@@ -161,7 +161,7 @@ - (void)example13
     MJChiBaoZiFooter *footer = [MJChiBaoZiFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
     
     // 当上拉刷新控件出现50%时(出现一半),就会自动刷新。这个值默认是1.0(也就是上拉刷新100%出现时,才会自动刷新)
-    //    footer.appearencePercentTriggerAutoRefresh = 0.5;
+    //    footer.triggerAutomaticallyRefreshPercent = 0.5;
     
     // 隐藏刷新状态的文字
     footer.refreshingTitleHidden = YES;
@@ -355,6 +355,9 @@ - (NSMutableArray *)data
 {
     if (!_data) {
         self.data = [NSMutableArray array];
+        for (int i = 0; i<5; i++) {
+            [self.data addObject:MJRandomData];
+        }
     }
     return _data;
 }

+ 1 - 1
README.md

@@ -139,7 +139,7 @@ UIView+MJExtension.h        UIView+MJExtension.m
 @property (assign, nonatomic, getter=isAutomaticallyRefresh) BOOL automaticallyRefresh;
 
 /** 当底部控件出现多少时就自动刷新(默认为1.0,也就是底部控件完全出现时,才会自动刷新) */
-@property (assign, nonatomic) CGFloat appearencePercentTriggerAutoRefresh;
+@property (assign, nonatomic) CGFloat triggerAutomaticallyRefreshPercent;
 @end
 ```