【问题标题】:Swift : how to blurry a cell on tap in tableViewSwift:如何在 tableView 中模糊点击单元格
【发布时间】:2014-11-18 18:19:00
【问题描述】:

我有一个显示照片的 tableView。 我只想添加一个 subView 以便在单元格顶部产生模糊效果。 我的问题是,当我使用 didSelectRowAtIndex 方法添加子视图时,我的子视图(我的模糊)被添加到重用的单元格中......

这就是我所做的:

  override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    let cell:WallTableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as WallTableViewCell



    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
    let blurEffectView = UIVisualEffectView(effect: blurEffect)
    blurEffectView.frame = cell.imagePosted.bounds


    cell.imagePosted.insertSubview(blurEffectView, atIndex: indexPath.row)


}

有没有办法使用点击识别器添加模糊效果,所以当我点击时会添加模糊,而当我第二次点击时会移除模糊?以及如何仅在被点击的单元格上添加模糊?

【问题讨论】:

    标签: ios uitableview swift addsubview


    【解决方案1】:

    问题是tableView.dequeueReusableCellWithIdentifier在这里调用的方法不对。

    你想调用cellForRowAtIndexPath,这是表格视图上的一个方法,它返回表格视图实际显示的单元格。您正在使用的 tableView.dequeueReusableCellWithIdentifier 提供了来自重用队列的“新”单元格。

    此外,您几乎肯定不想在didSelectRowAtIndexPath 中添加/删除子视图。相反,您可能应该将模糊子视图添加为原始单元设计的一部分,将它们设置为hidden=true,然后通过设置hidden=false 启用它们。

    【讨论】:

    • 感谢您,但是如何使用 cellForRowAtIndexPath 中的轻击手势识别器检测单元格是否模糊?我用 let tap 添加一个目标: UITapGestureRecognizer = UITapGestureRecognizer() cell.addGestureRecognizer(tap) tap.addTarget(self, action: "blurry") 我怎样才能得到索引路径?
    猜你喜欢
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多