Today, let's do a fun feature by swiping up and down to control the appearance and disappearance of the bottom button uitablview. First look at the effect:
Demand analysis
To do such a function, it should not be difficult for you, the way to achieve a lot. Let's take a look at some of the small functional points to implement:
Uitablview swipe up, bottom button disappears
Uitablview slide down, the bottom button appears
Uitablview slide to the bottom, the button appears
This is mainly the three small function points. So it's very simple, we just have to judge whether the Uitablview is going up, sliding down, and judging if the uitablview is sliding to the bottom.
Code implementation Create a bottom button
self.bottomButton = [UIButton buttonWithType:UIButtonTypeCustom];self.bottomButton.frame = CGRectMake(SCREEN.width / 2 - 25, SCREEN.height - 50, 50, 50);[self.bottomButton setBackgroundImage:[UIImage imageNamed:@"bottom"] forState:UIControlStateNormal];[self.view addSubview:self.bottomButton];
Now that the control button appears and disappears, first create a bottom button. Screen is a macro definition:
#define SCREEN [UIScreen mainScreen].bounds.size
Judging Uitablview swipe up and down
As we all know, Uitablview is inherited from Uiscrollview. So Uiscrollview's proxy method can be used in Uitablview. To determine uitablview up and down, we need to implement the Uiscrollview Scrollviewdidscroll: Proxy method:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (scrollView.contentOffset.y > self.offsetY && scrollView.contentOffset.y > 0) {//向上滑动 }else if (scrollView.contentOffset.y < self.offsetY ){//向上滑动 } self.offsetY = scrollView.contentOffset.y;//将当前位移变成缓存位移}
Judging Uitablview slide to the bottom
Also in the Scrollviewdidscroll: This method inside the judgment:
//判断滑动到底部if (scrollView.contentOffset.y == scrollView.contentSize.height - self.tableView.frame.size.height) {}
Button disappears and appears
//按钮消失[UIView transitionWithView:self.bottomButton duration:0.1 options:UIViewAnimationOptionTransitionNone animations:^{ self.bottomButton.frame = CGRectMake(SCREEN.width / 2 - 25, SCREEN.height, 50, 50); } completion:NULL];//按钮出现 [UIView transitionWithView:self.bottomButton duration:0.1 options:UIViewAnimationOptionTransitionNone animations:^{ self.bottomButton.frame = CGRectMake(SCREEN.width / 2 - 25, SCREEN.height - 50, 50, 50); } completion:NULL];
The button disappears is actually removes the screen, here I added a rotation of excessive animation, need what animation effect can choose. The button appears to set the frame of the button to the frame at the time of initialization.
This allows us to control the appearance and disappearance of the bottom button by sliding the Uitablview up and down. The code I have uploaded Github,iosstrongdemo is still:
Https://github.com/worldligang/iOSStrongDemo
If you think the article is good, please share to your classmates and friends, welcome to recommend them to focus on iOS development: Iosdevtip public number.
iOS dev > Learning-uitablview swipe up and down to control the appearance and disappearance of the bottom button