iOS dev > Learning-uitablview swipe up and down to control the appearance and disappearance of the bottom button

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.