2016-09-18 47 views
2

我在我的应用程序中实现了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) 
} 

回答

0

你升级到Swift3?如果是,请检查委托函数参数是否匹配。

此外,请记得检查registerForPreviewing是否正确调用。

registerForPreviewing(with: self as! UIViewControllerPreviewingDelegate, sourceView: view) 
+0

谢谢,但我还没有更新Swift 3在那个项目上(而且还没有想出这是什么问题) – CompC

+0

啊对。如果你分享你的viewControllerForLocation委托函数,我可以用我的版本检查它。 –

+0

我将我的代码添加到原始帖子中。 – CompC

0

运行Swift 3 migrator。 (编辑>转换>当前斯威夫特语法)

你似乎已经在使用雨燕3编译器 - 如果你仍然在斯威夫特2,方法调用你说的都是工作(如registerForPreviewing(with:sourceView:)tableView.cellForRow(at:))将无法编译,因为这些是这些API的Swift 3语法。

如果迁移失败,抓住它,你的委托方法雨燕3方法签名是previewingContext(_:viewControllerForLocation:) - 注意下划线表示有第一个参数没有参数的标签,所以你的声明应该是这样的:

func previewingContext(_ previewingContext: UIViewControllerPreviewing, 
    viewControllerForLocation location: CGPoint) -> UIViewController? 
+0

你说得对。这是来自一个旧版本,我试图更新到Swift 3,但我有一些与我使用的CocoaPods有关的问题。实际构建的项目版本位于Swift 2.3中。我更新了我的原始文章,以显示它实际上正在使用的代码(在Swift 2.3中 - 迁移仍然会给我提供pod方面的问题) – CompC

相关问题