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)
}
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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With