如何在3D Touch下注册预览单个单元格?

问题描述 投票:1回答:2

当前,我在viewDidLoad中具有以下代码:

if #available(iOS 9.0, *) {
    if traitCollection.forceTouchCapability == .Available {
        registerForPreviewingWithDelegate(self, sourceView: tableView)
    }
}

重点是,在这种情况下,模糊的是UITableView中的所有内容,而不是特定的UITableViewCell中的所有内容。

如何只暴露一个细胞?

[3d触摸期间此图像的状态。enter image description here

ios swift 3dtouch
2个回答
0
投票

这应该在viewDidLoad()中:

if traitCollection.forceTouchCapability == .available {
    registerForPreviewing(with: self, sourceView: tableView)
}

然后在previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint)中添加此:

guard let selectedIndexPath = tableView.indexPathForRow(at: location) else { return nil }
previewingContext.sourceRect = tableView.rectForRow(at: selectedIndexPath)

-1
投票

您做对了,您确实需要在viewDidLoad中注册预览。虽然,您还需要实现previewingContext方法,以提供源rect。基本上,您将单元作为源矩形,其外部的所有内容都将变得模糊。

请查看此Peek and Pop tutorial了解更多详细信息。

您也可以结帐the sample of code

© www.soinside.com 2019 - 2024. All rights reserved.