简体   繁体   English

应用程序在iPhone 6s的'偷看和弹出'实现中冻结

[英]App is freezing in 'peek and pop' implementation in iPhone 6s

I have implemented peek and pop in my app and it works perfectly. 我已经在我的应用程序中实现了窥视和弹出,它完美无缺。 But on continuously trying it for 7-8 times, the app freezes on peek view. 但是在不断尝试7-8次时,应用程序冻结在窥视视图上。 The only option I have is to kill the app and re-run. 我唯一的选择是杀死应用程序并重新运行。 Please let me know the reason for the freeze. 请让我知道冻结的原因。 I have used the following code for peek and pop in my project: 我在我的项目中使用了以下代码来查看和弹出:

var isPresentedBy3Dtouch: Bool = false
var passedDetails:DetailModel!

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {

  guard let indexPath = tableView?.indexPathForRowAtPoint(location)
    else { return nil }

  guard let cell = tableView?.cellForRowAtIndexPath(indexPath)
    else { return nil }

  guard let detailViewController = self.storyboard?.instantiateViewControllerWithIdentifier("Navigation") as? UINavigationController
    else { return nil }

   (detailViewController.topViewController as! DetailViewController).passedDetails = self.customerLists[indexPath.row]
   (detailViewController.topViewController as! DetailViewController).isPresentedBy3Dtouch = true
   detailVC.preferredContentSize = CGSize(width: 0.0, height: 480.0)
    previewingContext.sourceRect = cell.frame
    return detailVC
}

func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit :UIViewController) {
    showViewController(viewControllerToCommit, sender: self) 
}

This is an issue I have brought up to the engineers over at Apple months ago with no answer from them so far. 这是我几个月前在苹果工程师面前提出的一个问题,到目前为止他们没有回答。 If you debug the view hierarchy, you'll notice that a UITransitionView layer is the top-most view and it is not being removed. 如果您调试视图层次结构,您会注意到UITransitionView图层是最顶层的视图,并且未被删除。 That's what's causing the app to freeze. 这就是导致应用冻结的原因。 Actually, the functionality of the app isn't frozen - it still works as expected, but the UI is "stuck." 实际上,该应用程序的功能并未冻结 - 它仍然按预期工作,但UI“卡住”。 Here is my original post here on Stack Overflow: Force Touch animation freezes if gently touched 这是我在Stack Overflow上的原始帖子: 如果轻轻触摸,Force Touch动画会冻结

I found a reason for this bug. 我发现了这个错误的原因。

If your view controller need to support preview for force touch, you need register this vc with delegate by calling - (id <UIViewControllerPreviewing>)registerForPreviewingWithDelegate:(id<UIViewControllerPreviewingDelegate>)delegate sourceView:(UIView *)sourceView NS_AVAILABLE_IOS(9_0); 如果您的视图控制器需要支持强制触摸预览,则需要通过调用- (id <UIViewControllerPreviewing>)registerForPreviewingWithDelegate:(id<UIViewControllerPreviewingDelegate>)delegate sourceView:(UIView *)sourceView NS_AVAILABLE_IOS(9_0); method to do this. 这样做的方法。

I just suddenly call this function twice (once in super class 's viewDidLoad() , once in sub vc's), and when I remove once in my sub vc, this bug fixed! 我只是突然调用了这个函数两次(一次在超类的viewDidLoad() ,一次在sub vc中),当我在sub vc中删除一次时,这个错误修复了! Amazing... 惊人...

It's still an Apple bug since it makes no sence for that happens. 它仍然是一个Apple bug,因为它没有发生这种情况。 However, wish this answer can help developers who has the same issue with me. 但是,希望这个答案可以帮助那些与我有同样问题的开发人员。

I found another possible reason for this bug. 我发现了这个bug的另一个可能原因。

In the viewControllerForLocation I instantiated a view controller to show... 在viewControllerForLocation中,我实例化了一个视图控制器来显示...

func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
    let vc = VCImageFullScreen.loadView()
    return vc
}

...but this ViewController had a wrong super call in its viewDidAppear: ...但是这个ViewController在viewDidAppear中有一个错误的超级调用:

    class VCImageFullScreen : UIViewController {
        override func viewDidAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
            //BUG --> should be super.view**Did**Appear(animated)
            ...
        }
    }

After fixing this issue everything worked as expected. 修复此问题后,一切都按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM