Skip to content

Commit

Permalink
ViewDeckController swizzles the 'presentModalViewController:animated:…
Browse files Browse the repository at this point in the history
…' and '' with its own implementations.

These check if a viewdeckcontroller is present on the UIViewcontroller. If it is, it will delegate the presenting of the (modal) view to the viewdeckcontroller instead of the containing controller. This gives better results for rotation and presentation.

If no viewdeckcontroller is present, it just uses the standard implementation.

This also removes the code introduced by a remark of schemer in issue ViewDeck#28, since it's no longer applicable.
I'm not sure if this fixes ViewDeck#16?
  • Loading branch information
Inferis committed Feb 2, 2012
1 parent d4e9e93 commit 0a6aa34
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions ViewDeck/IIViewDeckController.m
Original file line number Diff line number Diff line change
Expand Up @@ -415,19 +415,9 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
_rightWidth = self.rightController.view.frame.size.width;
}

// heads up to @schemers for accounting with the modal views.
// see: https://github.com/Inferis/ViewDeck/issues/28

// let the viewdeckcontroller modalViewController handle the rotation behavior
UIViewController* rotateController = self.modalViewController;
// or, let the center controller modalViewController handle the rotation behavior
if (!rotateController) rotateController = self.centerController.modalViewController;
// or, let the center controller handle the rotation behavior
if (!rotateController) rotateController = self.centerController;

BOOL should = YES;
if (rotateController)
should = [rotateController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
if (self.centerController)
should = [self.centerController shouldAutorotateToInterfaceOrientation:interfaceOrientation];

return should;
}
Expand Down Expand Up @@ -1247,5 +1237,32 @@ - (void)setViewDeckController:(IIViewDeckController*)viewDeckController {
objc_setAssociatedObject(self, viewDeckControllerKey, viewDeckController, OBJC_ASSOCIATION_RETAIN);
}

- (void)vdc_presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated {
UIViewController* controller = self.viewDeckController ? self.viewDeckController : self;
[controller vdc_presentModalViewController:modalViewController animated:animated]; // when we get here, the vdc_ method is actually the old, real method
}

- (void)vdc_presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)animated completion:(void (^)(void))completion {
NSLog(@"presentvc = %@", self);
UIViewController* controller = self.viewDeckController ? self.viewDeckController : self;
[controller vdc_presentViewController:viewControllerToPresent animated:animated completion:completion]; // when we get here, the vdc_ method is actually the old, real method
}

+ (void)vdc_swizzle {
SEL presentModal = @selector(presentModalViewController:animated:);
SEL vdcPresentModal = @selector(vdc_presentModalViewController:animated:);
method_exchangeImplementations(class_getInstanceMethod(self, presentModal), class_getInstanceMethod(self, vdcPresentModal));

SEL presentVC = @selector(presentViewController:animated:completion:);
SEL vdcPresentVC = @selector(vdc_presentViewController:animated:completion:);
method_exchangeImplementations(class_getInstanceMethod(self, presentVC), class_getInstanceMethod(self, vdcPresentVC));
}

+ (void)load {
[super load];
[self vdc_swizzle];
}


@end

0 comments on commit 0a6aa34

Please sign in to comment.