我有一个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?