Skip to content

新增mj_scrollDirection,mj_scrollDistance#1181

Open
LevineKwok wants to merge 4 commits into
CoderMJLee:masterfrom
LevineKwok:LevineKwok-patch-1
Open

新增mj_scrollDirection,mj_scrollDistance#1181
LevineKwok wants to merge 4 commits into
CoderMJLee:masterfrom
LevineKwok:LevineKwok-patch-1

Conversation

@LevineKwok

Copy link
Copy Markdown

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

@LevineKwok

Copy link
Copy Markdown
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

kinarobin commented Jul 16, 2018

Copy link
Copy Markdown
Collaborator

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

@LevineKwok

Copy link
Copy Markdown
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
Copy Markdown
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

wolfcon commented Apr 24, 2019

Copy link
Copy Markdown
Collaborator

之所以提交这个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
Copy Markdown
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

3 participants