-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
新增mj_scrollDirection,mj_scrollDistance #1181
base: master
Are you sure you want to change the base?
Conversation
具体用法: #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];
} |
@LevineKwok Wouldn't it be better to use |
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. 😊 |
改动: 将 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];
} |
能给出一个 demo 来说明你的情况吗? 或者一段视频? |
/** Ma.).Mi ✎ | ||
* 如果是 UITableView | ||
*/ | ||
if ([self.delegate respondsToSelector:@selector(tableView:numberOfRowsInSection:)] || [self.delegate respondsToSelector:@selector(numberOfSectionsInTableView:)]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的判断. 不够优雅. 直接使用
if ([self isKindOfClass: UITableView.class]) {
// your implementation
}
之所以提交这个pull request, 是因为经常首页业务需要tabbar的隐藏,而往往都得去添加一个临时的previousOffsetY, 这样显得代码很ugly(个人认为,对比新增这两个属性,希望这两个属性在后面有更大的作为),所以冒昧提交。Thanks for review. 😊