3D Touch preferredContentSize不起作用

时间:2018-07-06 21:17:52

标签: ios swift 3dtouch

我有一个UIViewController和一个UIImageView。我将preferredContentSize设置为200x200,但是预览仍然占据了屏幕的整个宽度(减去边距)。

func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController?
{
    guard let indexPath = collectionView?.indexPathForItem(at: location)           else { return nil }
    guard let cell      = collectionView?.cellForItem(at: indexPath) as? ImageCell else { return nil }

    var controller: UIViewController

    controller = ImageViewController(image: cell.imageView.image as! Image)
    controller.preferredContentSize = CGSize(width: 200.0, height: 200.0)

    previewingContext.sourceRect = cell.frame

    return controller
}

为什么会这样,以及如何强制将预览设置为200x200?

0 个答案:

没有答案