美文网首页
iOS 模仿系统邮件App里搜索栏自动上滑或下滑

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

作者: 柳爷在深圳 | 来源:发表于2016-11-02 00:11 被阅读59次
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里搜索栏自动上滑或下滑

      本文链接:https://www.haomeiwen.com/subject/duhvuttx.html