ios - ios的折叠工具栏布局

标签 ios objective-c uitableview scroll parallax

我的应用程序有一个新设计,它包括一个用于在 tableView 顶部显示图像的视差滚动。

我知道如何通过将图像放入单元格来添加视差效果,就像这样 -

当调用表 scrollViewDidScroll 时:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    CGPoint currentOffset = scrollView.contentOffset;

        if (currentOffset.y > _lastContentOffset.y) {
            //Scroll Up

            _containerView.clipsToBounds = true;
            _bottomSpaceConstraint.constant = -scrollView.contentOffset.y / 2;
            _topSpaceConstraint.constant = scrollView.contentOffset.y / 2;

        } else {
           //Scroll Down

            _topSpaceConstraint.constant = scrollView.contentOffset.y;
            _containerView.clipsToBounds = false;

        } 

        _lastContentOffset = currentOffset;

}

(_bottomSpaceConstraint 和 _topSpaceConstraint 是第 0 节中 tableView 单元格内的图像顶部和底部约束)

但我的问题是,当图像达到我的导航栏大小时,我需要停止向上滚动图像。 (我的导航栏背景是透明的)我不希望图像一直位于顶部。但它是我的 tableView 内的一个单元格,所以它一直到顶部,直到它在滚动时消失。我需要帮助来阻止此图像滚动。如果要达到这个效果,可能我的做法不对。

这个效果是在 android 上的,它被称为“折叠工具栏布局”。 http://antonioleiva.com/collapsing-toolbar-layout/

有人知道如何为 iOS 实现这种“折叠工具栏布局”效果。

非常感谢您的帮助!

最佳答案

尝试创建一个包含图像的 UIView,并在 tableView 中设置 tableHeaderView。然后在 scrollViewDidScroll: 更新 header view 的高度和顶部约束。

关于ios - ios的折叠工具栏布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32563601/

相关文章:

IOS Apple 通用链接随机失败

ios - 使在 extern "C" block 中定义的类能够引用外部方法

objective-c - iPhone subview 设计(UIView 与 UIViewController)

iphone - 来自 NSUserDefaults 的对象正在释放?

iOS kAudioFileUnsupportedDataFormatError 在创建用于录音的音频文件时

ios - 加载不同的 xib

ios - 链 dismissViewControllerAnimated :completion and presentViewController:animated 时出错

iphone - SearchBar 从 iOS 7 的 headerview 中消失

ios - "property not found on object of type"prepareForSegue 中的错误尝试将参数发送到下一个 TableView Controller

ios - 在iOS模拟器中检测UIButton上的长按