Is there a way to get the view controller i'm transitioning out from inside :
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
When I'm using navigationController.topViewControll开发者_运维技巧er
I'm getting the one I'm moving into.
Using the navigationController.viewControllers
can suffice in case I'm getting deeper in the navigation system (cause I can look for the previous controller inside the array), but if I move "outside", this won't work, can the view controller I need is no longer there.
Any general way of doing it ? I need it so I can add to it a subview just during the animation, then of course it's gone.
Thanks
if you want to find a particular ViewController from array of navigation controller then try this.........
for(UIViewController * VC in [self.navigationController viewControllers])
{
if([VC isKindOfClass:[ViewController class]])
{
//YOUR CODE .......
}
}
Enjoy coding.........
I took a look a UINavigationControllerDelegate, and I'm pretty sure that if you try to implement this using the delegate, you're going to go through a lot of trouble to get this working right, when you could do it more easily and cleanly by using a subclass ofUINavigationController that overrides:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (UIViewController *)popViewControllerAnimated:(BOOL)animated;
and if you plan to use them
- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
and
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
You will also need to store the view to be added to the transitioning view, in the navigation controller, as an instance variable. In the example I will call it viewForTransition.
an example of one of the overridden methods:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
// Submit an animation which adds the viewForTransitioning to the view about to be pushed off screen.
// Upon completion, the animation will remove the viewForTransitioning from it's superview.
// You also need to figure out the proper duration and delay and store them in constants or as instance variables.
[UIView animateWithDuration:theDuration delay:theDelay options:UIViewAnimationOptionCurveLinear animations:^{
[self.topViewController.view addSubview:self.viewForTransition];
} completion:^{
[self.viewForTransition removeFromSuperview];
}];
// after submitting the animation, call super.
// if this makes the view appear for a few moments and then disappear before animating to the next view controller, you might try calling super after calling addSubview.
// if that doesn't work you can try storing the old top view controller in an instance variable so that it can be accessed by the delegate when navigationController:willShowViewController:animated: is called.
[super pushViewController:viewController animated:animated];
}
I'm not totally sure that this will do what you want. But it's worth a try.
精彩评论