Reputation: 1389
I was following the tutorial "A look inside View Controllers" posted from WWDC by apple for creating custom view controllers (video here: https://developer.apple.com/videos/wwdc/2014/ and sample code here: https://developer.apple.com/library/ios/samplecode/LookInside/Introduction/Intro.html). I've been mostly copying over their objective-C and translating it into Swift line by line and I've almost got it working except for hiding the overlay viewController with a gesture tap.
When I call:
func dimmingViewTapped(recognizer: UIGestureRecognizer) {
self.presentingViewController.dismissViewControllerAnimated(true, completion: nil)
}
I get an error: Thread 1: EXC_BAD_ACCESS (code=1, address=0xc) if the animated field is set to true. If it is set to false everything works perfectly fine and it disappears without animation). Another weird thing is it will sometimes work when set to true. Maybe once out of every 15 attempts the animation will complete and I won't get an error.
I'm following the exact same structure as defined in the sample code with a transitioning delegate handling the creation of the presentation controller object as well as the animations.
class OverlayTransitioningDelegate : NSObject, UIViewControllerTransitioningDelegate {
func presentationControllerForPresentedViewController(presented: UIViewController,
presentingViewController presenting: UIViewController,
sourceViewController source: UIViewController) -> UIPresentationController {
return OverlayPresentationController(presentedViewController: presented,
presentingViewController: presenting)
}
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
var animationController: OverlayAnimatedTransitioning = OverlayAnimatedTransitioning()
animationController.isPresentation = true
return animationController
}
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
var animationController: OverlayAnimatedTransitioning = OverlayAnimatedTransitioning()
animationController.isPresentation = false
return animationController
}
}
I know there have been a few questions out there regarding this but after reading them I'm still stumped and am looking for assistance.
Upvotes: 3
Views: 1943
Reputation: 626
This is instead of comment. But there shouldn't be difference between Swift , and Objective-C. TransitioningDelegate should be weak in both cases.
Upvotes: 0
Reputation:
Make sure your transitioning delegate is held strongly. Set it as a strong property on your controller.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SearchDetailsViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"SearchStoryboardID"];
viewController.delegate = self;
SearchDetailsViewControllerTransitioningDelegate *transitioningDelegate = [[SearchDetailsViewControllerTransitioningDelegate alloc] init];
**self.detailsTransitioningDelegate** = transitioningDelegate;
viewController.transitioningDelegate = (id <UIViewControllerTransitioningDelegate>)self.detailsTransitioningDelegate;
[self presentViewController:viewController animated:YES completion:nil];
Upvotes: 9