我在tableViewCell内部有一个按钮,在按钮内部有一个带有阴影的视图。在阴影视图的顶部,有一个按钮,可将阴影更改为看起来像被按下的视图。
我的问题是按下按钮与更新阴影之间存在延迟。
我知道该代码将立即运行,因此delaysContentTouches属性不是问题。我还可以看到代码在阴影更新行之前和之后运行,并且在按下按钮后立即运行。
我尝试将阴影更改为位于按钮上而不使用视图,但这会导致视图层次结构的其余部分产生大量问题。我已经重新连接了按钮功能。而且我尝试以编程方式实现整个过程。
我还有另一个按钮可以正常工作。唯一的区别是这些按钮在tableViewCell中。
这是更改阴影的功能。
@IBAction func touchDown(_ sender: UIButton) {
containerView.layer.shadowRadius = 1
containerView.layer.shadowOffset = CGSize(width: 0, height: 0.5)
containerView.layer.shadowPath = UIBezierPath(roundedRect: containerView.bounds, cornerRadius: 10).cgPath
}
@IBAction func touchUp(_ sender: UIButton) {
delegate?.pressedAt(indexPath!)
containerView.layer.shadowRadius = 2
containerView.layer.shadowOffset = CGSize(width: 0, height: 1)
containerView.layer.shadowPath = UIBezierPath(roundedRect: containerView.bounds, cornerRadius: 10).cgPath
}
我需要在按下按钮时立即更改阴影。这是为了显示视图正像按钮一样被按下。