【发布时间】:2016-09-18 05:16:56
【问题描述】:
我在我的应用程序中实现了 3D 触摸,通过将我的视图控制器与我的表格视图注册为源矩形。自从我实施它以来,过去几周它一直运行良好。
但我只是尝试了一下,发现它似乎不再起作用了。我没有接触任何代码,所以我不知道问题是什么。
视图控制器肯定是为UIViewControllerPreviewing 注册的,但previewingContext(previewingContext: viewControllerForLocation:) 甚至没有被调用!
我不知道除了注册预览之外还有什么要做的设置,而且我所做的任何事情似乎都不会触发该方法。我有一个单独的视图控制器,其中 3D 触摸似乎工作正常,但我没有做任何不同的事情。
有没有人知道为什么该方法甚至没有被调用?这真的让我很沮丧,因为它似乎已经停止工作,因为它之前工作正常。谢谢。
这是我的previewingContext(previewingContext: viewControllerForLocation:) 方法的代码:
func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
let identifier = "ClipPlayerViewController"
guard let indexPath = tableView.indexPathForRowAtPoint(location), let destination = storyboard?.instantiateViewControllerWithIdentifier(identifier) as? ClipPlayerViewController else { return nil }
let effect = filteredEffectsSortedBySection[indexPath.section].effects[indexPath.row]
switch effect.mediaType {
case .Video:
destination.effect = effect
destination.showsPlaybackControls = false
if let thumbnail = thumbnailsForEffects[effect], let unwrappedThumbnail = thumbnail {
destination.preferredContentSize = CGSizeMake(unwrappedThumbnail.size.width - 2, unwrappedThumbnail.size.height - 2)
} else if let effectSize = destination.player?.currentItem?.asset.tracksWithMediaType(AVMediaTypeVideo).first?.naturalSize {
destination.preferredContentSize = effectSize
}
previewingContext.sourceRect = tableView.cellForRowAtIndexPath(indexPath)!.frame
return destination
case .Texture:
return nytPhotosViewControllerForEffectAtIndexPath(indexPath)
}
}
这是我注册预览的代码,在viewDidLoad()中调用:
if traitCollection.forceTouchCapability == .Available {
registerForPreviewingWithDelegate(self, sourceView: tableView)
}
【问题讨论】:
标签: ios iphone uiviewcontroller uikit 3dtouch