I am hiding the Navigation Bar of a UINavigationController by sending the message:
[self.navigationController setNavigationBarHidden:YES animated:YES];
I'd like to know if there is any change to get a callback or completion block when the animation completes. Something like:
[UIView animateWithDuration:0.7 animations:^{
}completion:^(BOOL finished){
}];
This works for my, hope this help.
God luck!
[UIView transitionWithView:self.view
duration:UINavigationControllerHideShowBarDuration
options:UIViewAnimationCurveEaseOut
animations:^{
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden];
}
completion:^(BOOL finished){
NSLog(#"hide animation finished");
}];
Related
Is there a way to adjust the duration and curve of the setNavigationBarHidden method of a UINavigationController? It appears far too quickly and does not mesh with the other animations on my app.
You could create your own hide animation as follows:
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.navigationController.navigationBar.alpha = 0;
} completion:^(BOOL finished) {
[self.navigationController setNavigationBarHidden:YES animated:NO];
}];
I have an UIView with a pic inside (65x65) and I want to "flip" this UIView with a blank UIView but it doesn't work. I only can flip my view with the same view, when I'm adding the blank view, it works but not with the flip animation.
Here is my code who works :
[UIView transitionWithView:myView
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
//[myView removeFromSuperview];
// [self.view addSubview:tmp];
}
completion:^(BOOL finished){
[myView removeFromSuperview];
}];
The commented part is what I was trying to do, "tmp" is the blank UIView (init with myView.frame) and of course I remove the line in the "completion" part.
What am I doing wrong ?
Thanks for you help.
Try this
[UIView transitionFromView:myView toView:tmp duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
[myView removeFromSuperview];
}];
I'm trying to animate a view with some buttons and controllers for my main view into the screen from the right side of the screen. The problem is it doesn't animate, it just goes directly to the finished state.
This is my code:
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
options = [storyBoard instantiateViewControllerWithIdentifier:#"OptionsView"];
options.delegate = self;
[self.view addSubview:options.view];
options.view.center = CGPointMake(floor(total_width+options.view.frame.size.width/2)+10, floor(total_height/2));
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
options.view.center = CGPointMake(floor(total_width-options.view.frame.size.width/2)+10, floor(total_height/2));
}
completion:^(BOOL finished){
NSLog(#"Done!");
}];
EDIT
To make things more strange, if I put this animation inside the completion block of another animation then this one works, but not the new one.
UIButton* boton = (UIButton*) sender;
[UIView animateWithDuration:5.0
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
boton.alpha = 0.0;
//Jumps directly to 0, animation doesn't work
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
options.view.center = CGPointMake(floor(total_width-options.view.frame.size.width/2)+10, floor(total_height/2));
//It works now, but it doesn't take 5 seconds to start, it starts right away
}
completion:^(BOOL finished){
NSLog(#"Done!");
}];
}];
The line before the animateWithDuration:... call directly assigns the center to the same value that you're animating to. Either remove that or assign the initial center value there. An animation that has the same start and end values obviously has no effect.
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.connectionIndicator = [[[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
[self.view addSubview:connectionIndicator];
[self.connectionIndicator setCenter:CGPointMake(self.view.frame.size.width/2, 15)];
[connectionIndicator startAnimating];
}
The spinner shows up frozen, and does not start animating.
Edit: Okay I figured out the cause but yet to find a solution.
This view controller is pushed into navigation controller stack through a page curl-up transition:
ServerHandshakeViewController *shvc = [[ServerHandshakeViewController alloc] initWithHost:h];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[self.navigationController pushViewController:shvc animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[shvc release];
Removing the above curl-up transition like below solves the spinner freeze problem.
ServerHandshakeViewController *shvc = [[ServerHandshakeViewController alloc] initWithHost:h];
[self.navigationController pushViewController:shvc animated:NO];
[shvc release];
But then, what if I want to retain my curl-up page transition?
You could try using the block method where you can specify animation options. UIViewAnimationOptionAllowAnimatedContent is the option which should free up the spinner.
[UIView transitionWithView:self.navigationController.view
duration:1.0
options:UIViewAnimationOptionAllowAnimatedContent | UIViewAnimationTransitionCurlUp | UIViewAnimationOptionCurveEaseInOut
animations:^{[self.navigationController pushViewController:shvc animated:NO];}
completion:nil];
I have a UIViewController that should control 2 UIImageViews to fade in.
I managed to animate them using the UIView animateWithDuration method, like this:
[UIView animateWithDuration:1.5
animations:^{
[mFrontpageTitle setAlpha:0];
[mFrontpageTitle setAlpha:1];
}
completion:^(BOOL finished){
[self AnimatePause];
}];
and
-(void)AnimatePause {
[UIView animateWithDuration:5.0
animations:^{
[mFrontpageTitle setAlpha:0.99];
[mFrontpageTitle setAlpha:1];
}
completion:^(BOOL finished){
[self AnimateAuthor];
}];
which fires the next animation. Now, creating a transition from .99 to 1.0 is not very clean.
Is there a better way to trigger a block or sending a message by just defining a duration?
thanks
Zuppa
NSTimeInterval delay = 1.5; //in seconds
[self performSelector:#selector(myMethod) withObject:nil afterDelay:delay];