美文网首页iOS开发技术分享
iOS - UIScrollView滚动方向 & UIV

iOS - UIScrollView滚动方向 & UIV

作者: MonsterNanny | 来源:发表于2016-05-05 14:27 被阅读3065次

判断UIScrollView滚动方向, 以下是 "判断上下" 的代码

float lastContentOffset;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    lastContentOffset = scrollView.contentOffset.y;
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
    if (lastContentOffset < scrollView.contentOffset.y) {
        [UIView animateWithDuration:0.5 animations:^{
            self.headerViewTopConstraint.constant = -self.headerView.frame.size.height;
            [self.headerView layoutIfNeeded];
        }];
    }else{
        JXLog(@"向下滚动");
        [UIView animateWithDuration:0.1 animations:^{
            self.headerViewTopConstraint.constant = 0;
            [self.headerView layoutIfNeeded];
        }];
}

左右同理判断换成 : scrollView.contentOffset.x

UIView的Animation无效

只需要在动画代码块调用UIView的 [self.view layoutIfNeeded];方法即可

相关文章

网友评论

    本文标题:iOS - UIScrollView滚动方向 & UIV

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