Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

新增mj_scrollDirection,mj_scrollDistance #1181

wants to merge 4 commits into from

Conversation

LevineKwok
Copy link

之所以提交这个pull request, 是因为经常首页业务需要tabbar的隐藏,而往往都得去添加一个临时的previousOffsetY, 这样显得代码很ugly(个人认为,对比新增这两个属性,希望这两个属性在后面有更大的作为),所以冒昧提交。Thanks for review. 😊

@LevineKwok
Copy link
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];
}

@kinarobin
Copy link
Collaborator

kinarobin commented Jul 16, 2018

@LevineKwok Wouldn't it be better to use NS_ENUM(...) for mj_scrollDirection?😁😁

@LevineKwok
Copy link
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. 😊

@LevineKwok
Copy link
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];
}

@wolfcon
Copy link
Collaborator

wolfcon commented Apr 24, 2019

之所以提交这个pull request, 是因为经常首页业务需要tabbar的隐藏,而往往都得去添加一个临时的previousOffsetY, 这样显得代码很ugly(个人认为,对比新增这两个属性,希望这两个属性在后面有更大的作为),所以冒昧提交。Thanks for review. 😊

能给出一个 demo 来说明你的情况吗? 或者一段视频?
因为这2个属性对于这个库来说没有作用(至少是现阶段, 或许支持 CollectionView 的左划刷新会用到?)

/** Ma.).Mi ✎
* 如果是 UITableView
*/
if ([self.delegate respondsToSelector:@selector(tableView:numberOfRowsInSection:)] || [self.delegate respondsToSelector:@selector(numberOfSectionsInTableView:)]) {
Copy link
Collaborator

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants