[英]Swift : how to blurry a cell on tap in tableView
我有一个显示照片的tableView。 我只想添加一个subView,以使单元格顶部具有模糊效果。 我的问题是,当我使用didSelectRowAtIndex方法添加subView时,我的subView(模糊)被添加到重用的单元格中...
这是我所做的:
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)
}
有没有一种方法可以使用拍子识别器添加模糊效果,所以当我点击模糊时,当我再次点击模糊时,模糊被消除了? 以及如何仅在被点击的单元格上添加模糊?
问题是tableView.dequeueReusableCellWithIdentifier
是在此处调用的错误方法。
您要调用cellForRowAtIndexPath
,这是表视图上的一种方法,该方法返回表视图实际显示的单元格。 您正在使用的tableView.dequeueReusableCellWithIdentifier
提供了重用队列中的“新鲜”单元格。
另外,您几乎可以肯定不想在didSelectRowAtIndexPath
添加/删除子视图。 相反,您可能应该将模糊子视图添加为原始单元格设计的一部分,将其设置为hidden=true
,然后通过设置hidden=false
启用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.