Skip to content

Commit

Permalink
Back footer position
Browse files Browse the repository at this point in the history
Back footer position
  • Loading branch information
CoderMJLee committed Sep 8, 2015
1 parent 16d9766 commit 1cfebd7
Show file tree
Hide file tree
Showing 17 changed files with 137 additions and 44 deletions.
48 changes: 37 additions & 11 deletions MJRefresh.podspec
Original file line number Diff line number Diff line change
@@ -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' => '[email protected]'}
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' => '[email protected]'}
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
5 changes: 4 additions & 1 deletion MJRefresh/Base/MJRefreshAutoFooter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 14 additions & 3 deletions MJRefresh/Base/MJRefreshAutoFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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];
Expand Down
9 changes: 8 additions & 1 deletion MJRefresh/Base/MJRefreshBackFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions MJRefresh/Base/MJRefreshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ typedef void (^MJRefreshComponentRefreshingBlock)();
/** 当scrollView的拖拽状态发生改变的时候调用 */
- (void)scrollViewPanStateDidChange:(NSDictionary *)change;


#pragma mark - 其他
/** 拉拽的百分比(交给子类重写) */
@property (assign, nonatomic) CGFloat pullingPercent;
Expand Down
9 changes: 7 additions & 2 deletions MJRefresh/Base/MJRefreshComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,7 +67,7 @@ - (void)willMoveToSuperview:(UIView *)newSuperview
// 设置永远支持垂直弹簧效果
_scrollView.alwaysBounceVertical = YES;
// 记录UIScrollView最开始的contentInset
_scrollViewOriginalInset = self.scrollView.contentInset;
_scrollViewOriginalInset = _scrollView.contentInset;

// 添加监听
[self addObservers];
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions MJRefresh/Base/MJRefreshHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions MJRefresh/UIScrollView+MJRefresh.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions MJRefreshExample/MJRefreshExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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>"; };
Expand Down Expand Up @@ -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>";
Expand Down Expand Up @@ -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 */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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"/>
Expand Down
22 changes: 2 additions & 20 deletions MJRefreshExample/MJRefreshExample/Classes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
//

#import "AppDelegate.h"
#import "MJExampleWindow.h"

@interface AppDelegate ()
@property (strong, nonatomic) UIWindow *alert;
@end

@implementation AppDelegate
Expand All @@ -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.
Expand All @@ -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];
});
}

Expand Down
13 changes: 13 additions & 0 deletions MJRefreshExample/MJRefreshExample/Classes/MJExampleWindow.h
Original file line number Diff line number Diff line change
@@ -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 changes: 37 additions & 0 deletions MJRefreshExample/MJRefreshExample/Classes/MJExampleWindow.m
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ - (void)viewDidLoad {
}];
footer.hidden = YES;
tableView.footer = footer;
// tableView.footer.automaticallyChangeAlpha = YES;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down

0 comments on commit 1cfebd7

Please sign in to comment.