What is wrong with this iOS animation block?
+ (void) AnimateSwitchingWithParent: (UIViewController *) ParentController From: (UIViewController *) From To: (UIViewController* ) To {
To.view.frame = ParentController.view.bounds;
[UIView transitionFromView:From.view toView:To.view
duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];
ParentController.view = To.view;
[To viewWillAppear:true];
}
this is my func开发者_开发知识库tion to make animation that will be called if want to change view from 1 view to another view, but I have problem, I have a viewController named filter, at there I have Button called Reset that will reset all of content inside but to show that the reset have done, I want to call
[self AnimateSwitchingWithParent:self From:self To:self];
but the result is My View was blank. how can it be? any one have another way?
If you have to flip the current view controller's view while resetting content, use the transitionWithView:duration:options:animations:completion:
method.
Example
[UIView transitionWithView:self.view
duration:1.0f
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^(void) {
[self resetStuff];
}
completion:nil];
Side Note
You current implementation in the question will be useful to switching views in the view hierarchy. Say From.view
is the subview of ParentController.view
then the statement below will replace From.view
with To.view
as the subview of ParentController.view
.
[UIView transitionFromView:From.view toView:To.view
duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL];
You definitely don't need to do this,
ParentController.view = To.view;
Doing that will replace the ParentController
's view
which might be different from what you intended and definitely in contradiction to the transition animation on the line before.
You must definitely not be calling,
[To viewWillAppear:true];
directly.
To my understanding you should be able to remove the last two lines.
精彩评论