我在我的應用程序中實現了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