新增mj_scrollDirection,mj_scrollDistance#1181
Open
LevineKwok wants to merge 4 commits intoCoderMJLee:masterfrom
LevineKwok:LevineKwok-patch-1
Open
新增mj_scrollDirection,mj_scrollDistance#1181LevineKwok wants to merge 4 commits intoCoderMJLee:masterfrom LevineKwok:LevineKwok-patch-1
LevineKwok wants to merge 4 commits intoCoderMJLee:masterfrom
LevineKwok:LevineKwok-patch-1
Conversation
Author
|
具体用法: #pragma mark #Ma.).Mi# - scrollview action
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
UITabBarController *rootController = (UITabBarController *)self.navigationController.parentViewController;
UITabBar *tabBar = rootController.tabBar;
[UIView animateWithDuration:0.3f delay:0.f options:UIViewAnimationOptionCurveEaseInOut animations:^{
NSString *direction = scrollView.mj_scrollDirection;
NSInteger distance = scrollView.mj_scrollDistance;
/** Ma.).Mi ✎
* 第一种:通过 distance 判断
*/
if (distance > 0) {
CGRect newRect = CGRectMake(0, SCREEN_HEIGHT + self.getTabBarHeight, SCREEN_WIDTH, self.getTabBarHeight);
[tabBar setFrame:newRect];
} else {
CGRect newRect = CGRectMake(0, SCREEN_HEIGHT - self.getTabBarHeight, SCREEN_WIDTH, self.getTabBarHeight);
[tabBar setFrame:newRect];
}
/** Ma.).Mi ✎
* 第二种:通过 direction 判断
*/
if ([direction isEqualToString:@"bottom"]) {
CGRect newRect = CGRectMake(0, SCREEN_HEIGHT + self.getTabBarHeight, SCREEN_WIDTH, self.getTabBarHeight);
[tabBar setFrame:newRect];
} else {
CGRect newRect = CGRectMake(0, SCREEN_HEIGHT - self.getTabBarHeight, SCREEN_WIDTH, self.getTabBarHeight);
[tabBar setFrame:newRect];
}
} completion:nil];
} |
Collaborator
|
@LevineKwok Wouldn't it be better to use |
Author
|
Yeah, you are right. I prefer to use NS_ENUM(...) before, but i found that is not the most important part, but now i think it's the good idea when programmer have some switch case about scrollDirection. Thanks for your advice. 😊 |
Author
|
改动: 将 mj_scrollDirection 类型改为 enum ScrollDirection, 方便 switch case 情况的维护: #pragma mark #Ma.).Mi# - scrollview action
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
UITabBarController *rootController = (UITabBarController *)self.navigationController.parentViewController;
UITabBar *tabBar = rootController.tabBar;
[UIView animateWithDuration:0.3f delay:0.f options:UIViewAnimationOptionCurveEaseInOut animations:^{
/** Ma.).Mi ✎
* 第一种:通过 distance 判断
*/
NSInteger distance = scrollView.mj_scrollDistance;
if (distance > 0) {
CGRect newRect = CGRectMake(0, SCREEN_HEIGHT + self.getTabBarHeight, SCREEN_WIDTH, self.getTabBarHeight);
[tabBar setFrame:newRect];
} else {
CGRect newRect = CGRectMake(0, SCREEN_HEIGHT - self.getTabBarHeight, SCREEN_WIDTH, self.getTabBarHeight);
[tabBar setFrame:newRect];
}
/** Ma.).Mi ✎
* 第二种:通过 direction 判断
*/
ScrollDirection direction = scrollView.mj_scrollDirection;
switch (direction) {
case Bottom: {
CGRect newRect = CGRectMake(0, SCREEN_HEIGHT + TABBAR_HEIGHT, SCREEN_WIDTH, TABBAR_HEIGHT);
[self.emuleTabbar setFrame:newRect];
}
break;
default: {
CGRect newRect = CGRectMake(0, SCREEN_HEIGHT - TABBAR_HEIGHT, SCREEN_WIDTH, TABBAR_HEIGHT);
[self.emuleTabbar setFrame:newRect];
}
break;
}
} completion:nil];
} |
Collaborator
能给出一个 demo 来说明你的情况吗? 或者一段视频? |
wolfcon
reviewed
Apr 24, 2019
| /** Ma.).Mi ✎ | ||
| * 如果是 UITableView | ||
| */ | ||
| if ([self.delegate respondsToSelector:@selector(tableView:numberOfRowsInSection:)] || [self.delegate respondsToSelector:@selector(numberOfSectionsInTableView:)]) { |
Collaborator
There was a problem hiding this comment.
这里的判断. 不够优雅. 直接使用
if ([self isKindOfClass: UITableView.class]) {
// your implementation
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
之所以提交这个pull request, 是因为经常首页业务需要tabbar的隐藏,而往往都得去添加一个临时的previousOffsetY, 这样显得代码很ugly(个人认为,对比新增这两个属性,希望这两个属性在后面有更大的作为),所以冒昧提交。Thanks for review. 😊