ios - 当 UIScrollView 滚动时,导航和工具栏不会隐藏

标签 ios xcode uiscrollview contentoffset

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    lastOffset = scrollView.contentOffset;

    if (scrollView.contentOffset.y < lastOffset.y) {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        [self.navigationController setToolbarHidden:YES animated:YES];
    }
    else {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        [self.navigationController setToolbarHidden:NO animated:YES];
    }
}

我做错了什么? UIScrollViewDelegate 已在我的头文件中设置。

最佳答案

你应该移动

lastOffset = scrollView.contentOffset;

到方法结束,否则

scrollView.contentOffset.y < lastOffset.y

永远不会是真的。

关于ios - 当 UIScrollView 滚动时,导航和工具栏不会隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12184865/

相关文章:

ios - 同时执行多个异步请求

ios - 在内存不足时防止 ViewDidUnload?

Xcode 7 Playground 标记 : What is keyboard shortcut for Show Rendered Markup

ios - UIScrollView 运行时 View 变化

ios - 如何在 Swift 5 中添加 ScrollView ?

ios - 访问自定义 UITableView 单元格的属性

php - iOS 和 PHP 使用的时间戳格式有区别吗?

iphone - 是否可以在未安装 Xcode 的情况下在 Mac 上运行 iOS 模拟器?

xcode - 如何在 NSViewController 中重新加载数据?

ios - 如何根据键盘管理 ScrollView (向上和向下)在 Objective-C 中使用 NSNotificationCenter 在屏幕中显示和隐藏