我在我的应用程序中实现了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)
}
谢谢,但我还没有更新Swift 3在那个项目上(而且还没有想出这是什么问题) – CompC
啊对。如果你分享你的viewControllerForLocation委托函数,我可以用我的版本检查它。 –
我将我的代码添加到原始帖子中。 – CompC