iOS 模仿系统邮件App里搜索栏自动上滑或下滑

UIView *customView = [[UIView alloc] initWithFrame:CGRectFrame(0, 0, 320, 50)]; // 自定义视图

self.tableView.tableHeaderView = customView;

#pragma mark - UIScrollView delegate methods
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    [UIView animateWithDuration:0.3
                     animations:^{
                        if (scrollView.contentOffset.y < 25)
                        {
                            scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
                        }
                        else if (scrollView.contentOffset.y < 50)
                        {
                            scrollView.contentInset = UIEdgeInsetsMake(-50, 0, 0, 0);
                        }
    }];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (scrollView == self.tableView)
    {
        if (!decelerate)
        {
            [UIView animateWithDuration:0.3
                                       animations:^{
                                            if (scrollView.contentOffset.y < 25)
                                            {
                                                 scrollView.contentOffset = CGPointMake(0, 0);
                                            }
                                            else if (scrollView.contentOffset.y < 50)
                                           {
                                                scrollView.contentOffset = CGPointMake(0, 50);
                                           }
                                     }];
            }
    }
}

你可能感兴趣的:(iOS 模仿系统邮件App里搜索栏自动上滑或下滑)