MJRefresh icon indicating copy to clipboard operation
MJRefresh copied to clipboard

新增mj_scrollDirection,mj_scrollDistance

Open LevineKwok opened this issue 6 years ago • 5 comments

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

LevineKwok avatar Jul 15 '18 18:07 LevineKwok

具体用法:

#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 avatar Jul 15 '18 18:07 LevineKwok

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

kinarobin avatar Jul 16 '18 01:07 kinarobin

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 avatar Jul 16 '18 05:07 LevineKwok

改动: 将 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];
}

LevineKwok avatar Jul 16 '18 06:07 LevineKwok

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

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

wolfcon avatar Apr 24 '19 01:04 wolfcon