繁体   English   中英

在swift中添加UIVisualEffectView到tableView

[英]Adding UIVisualEffectView to tableView in swift

我在storyBoard中的tableView顶部的Xcode中添加了一个UIVisualEffectView对象形式的Object Library。 tableView的第一个单元格位于UIVisualEffectView对象的后面。 我想在模糊区域下方显示表格视图的第一个单元格。 此外,当我滚动表格单元格时,它应该在模糊区域后面。 我试过这个代码

self.tableView.contentInset = UIEdgeInsetsMake(100, 0, 0, 0)
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(100, 0, 0, 0)

但是当我向上滚动时,细胞不会落在模糊区域后面。 救命

此外,我正在尝试更改模糊区域的颜色。 目前它的白色为光效,黑色为暗效果。 如何设置特定颜色以模糊区域而不影响其行为?

你的细胞不能走到桌子外面。 所以你需要扩展tableView,然后添加contentInset。

还要确保tableView是透明的,visualEffectView在tableView下。

例如,简单的方法是将UIVisualEffectView作为表视图节标题视图

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let blurEffect = UIBlurEffect(style: .Light)
    let blurView = UIVisualEffectView(effect: blurEffect)
    return blurView
}

override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 44.0
}

看起来像 在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM