如何在使用3D Touch Peek功能时为表格视图单元格中的项目实现浮动动画?

时间:2018-06-06 19:02:37

标签: ios swift 3dtouch

我实施了3D Touch Peek&使用以下代码示例在我的应用程序中启动:

extension ParentVC: UIViewControllerPreviewingDelegate
{
    func previewingContext(_ previewingContext: UIViewControllerPreviewing,
                           viewControllerForLocation location: CGPoint) -> UIViewController?
    {
        guard let indexPath = mmTableView?.indexPathForRow(at: location) else { return nil }

        guard let cell = myTableView.cellForRow(at: indexPath) else { return nil }

        guard let detailsVC = storyboard?.instantiateViewController(withIdentifier: "ChildVC") as?
            ChildVC else {
                return nil
        }

        detailsVC.manager = manager

        guard let detailsManager = detailsVC.manager else {
            return nil
        }
        previewingContext.sourceRect = cell.frame

        return detailsManager.previewDetails(indexPath: indexPath, detailsVC: detailsVC)
    }

    func previewingContext(_ previewingContext: UIViewControllerPreviewing,
                           commit viewControllerToCommit: UIViewController)
    {
        navigationController?.pushViewController(viewControllerToCommit,
                                                 animated: true)
    }
}

class ParentVC: UIViewController
{
    var manager = Manager()

    override func viewDidLoad()
    {
        super.viewDidLoad()

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

        ...
}

class Manager: NSObject
{
    ...

        public func previewClothingDetails(indexPath: IndexPath, detailsVC: ChildVC) -> ChildVC
    {
        // Set text and image in ChildVC here

        detailsVC.preferredContentSize = CGSize(width: 0.0,
                                                height: 320.0)

        return detailsVC
    }
}

结果:

enter image description here

我喜欢实现的内容如下所示:iOS App Store中可以看到:

enter image description here

如果您注意到,当启动3D Peek手势时,文本,图像以及GET按钮都有弹出动画,并且显示为浮动,但单元格不会移动,与我的不同。

如何复制此动画?

0 个答案:

没有答案