简体   繁体   English

在swift中添加UIVisualEffectView到tableView

[英]Adding UIVisualEffectView to tableView in swift

I have added a UIVisualEffectView object form Object Library in Xcode on top of my tableView in the storyBoard. 我在storyBoard中的tableView顶部的Xcode中添加了一个UIVisualEffectView对象形式的Object Library。 The first cell of the tableView is behind the UIVisualEffectView object . tableView的第一个单元格位于UIVisualEffectView对象的后面。 I want to display the first cell of the table view below the blur area. 我想在模糊区域下方显示表格视图的第一个单元格。 Also when i scroll the table cells it should go behind the blur area . 此外,当我滚动表格单元格时,它应该在模糊区域后面。 I tried with this code 我试过这个代码

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

But when i scroll upside the cells won't go behind the blur area . 但是当我向上滚动时,细胞不会落在模糊区域后面。 Help 救命

Also I am trying to change the color of the blur region. 此外,我正在尝试更改模糊区域的颜色。 Currently its white for light effect and black for dark effect. 目前它的白色为光效,黑色为暗效果。 How do i set a specific color to blur area without effecting its behavior ? 如何设置特定颜色以模糊区域而不影响其行为?

Yours cell cant go outside of the table. 你的细胞不能走到桌子外面。 So you need to extend the tableView, then add contentInset. 所以你需要扩展tableView,然后添加contentInset。

Also make sure that your tableView is transparent and visualEffectView is under the tableView. 还要确保tableView是透明的,visualEffectView在tableView下。

Simple method is make UIVisualEffectView as your table view section header view, for example 例如,简单的方法是将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
}

it looks like 看起来像 在此输入图像描述

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

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