Я хочу добавить UIPreviewInteraction к своему UITableViewCell
, чтобы я мог воссоздать что-то похожее на действие Apple Touch 3D Touch.Вот что я сделал в своем UITableView's
cellForRowAt
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
let interactionView = cell?.viewWithTag(1) as! UIView
if #available(iOS 10.0, *) {
var planPreviewInteraction = UIPreviewInteraction(view: interactionView)
previewInteraction.delegate = self
}
return cell!
}
, а затем я вызываю функции делегата
func previewInteraction(_ previewInteraction: UIPreviewInteraction, didUpdatePreviewTransition transitionProgress: CGFloat, ended: Bool) {
let buttonPosition = previewInteraction.view?.convert(CGPoint.zero, to: self.tableView)
let indexPath = self.tableView.indexPathForRow(at: buttonPosition!)
animator.fractionComplete = transitionProgress
}
func previewInteractionDidCancel(_ previewInteraction: UIPreviewInteraction) {
}
Но методы делегата никогда не вызываются.Не похоже, что UITableViewCell
обнаруживает UIPreviewInteraction
.Может кто-то помочь мне с этим?