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

こ雲淡風輕ζ 提交于 2019-12-07 01:42:04

问题


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. 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) 
}

回答1:


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. 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." Here is my original post here on Stack Overflow: Force Touch animation freezes if gently touched




回答2:


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); 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! Amazing...

It's still an Apple bug since it makes no sence for that happens. However, wish this answer can help developers who has the same issue with me.




回答3:


I found another possible reason for this bug.

In the viewControllerForLocation I instantiated a view controller to show...

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:

    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.



来源:https://stackoverflow.com/questions/35934956/app-is-freezing-in-peek-and-pop-implementation-in-iphone-6s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!