ios - 在 iOS 6 中更改 tableHeaderView 的框架时,UITableView 不会自动调整大小

标签 ios

我通过使用 tableHeaderView 并在滚动时调整框架的大小在 UITableView 中实现了视差效果:

headerView is the table.tableHeaderView
topHeight = 400; // the height of the tableHeaderView

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat scrollOffset = scrollView.contentOffset.y;
    if (scrollOffset>=0 && scrollOffset<=topHeight) {
        CGRect frame = CGRectMake(0, scrollOffset/2, 320, topHeight - scrollOffset/2);
        headerView.frame = frame;
    } else if (scrollOffset>topHeight) {
        CGRect frame = CGRectMake(0, 100, 320, 100);
        headerView.frame = frame;
    } else {
        CGRect frame = CGRectMake(0, 0, 320, topHeight);
        headerView.frame = frame;
    }
}

该效果在 iOS 5.0 和 5.1 上完美运行,但我在 iOS 6+ 上的 tableHeaderView 和表格内容之间出现一些奇怪的空间(图像中的标题为红色)

iOS 5 - 标题和表格内容之间没有空格: iOS 5 - no space between the header and the table content

iOS 6 0 表头与表内容间隔开: iOS 6 0 header is spaced from the table content

最佳答案

需要重新设置tableHeaderView:

table.tableHeaderView = table.tableHeaderView;

关于ios - 在 iOS 6 中更改 tableHeaderView 的框架时,UITableView 不会自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13721503/

相关文章:

ios - 添加和删​​除事务队列观察器 - 正确的方法?

ios - 是否可以在拆分模式下为屏幕的全宽在键盘上方创建 inputAccessoryView?

ios - addPeriodicTimeObserver保留AVPlayer实例

iphone - 更新推送通知角标(Badge)计数

ios - Xcode iOS 模拟器离开 Black Space

objective-c - 在 UIScrollview 中设置 size 属性

ios - Playground——DispatchQueue和DispatchSemaphore的关系

iOS AVAudioSession,如何访问AVAudioRecorder 电平表

ios - 如何在 cocos2d 中播放来自 url 的音乐文件

ios - 静态方法中的 UIAlertController 给出错误 : extra argument animated in cell