Hide/Show NavigationBar & Toolbar on tap - iphone

I'm trying to hide my navigationBar and toolbars on tap, similar to the way the Photos application works.
Any pointers would be greatly appreciated.
Thanks!

This works too :)
[self.navigationController setNavigationBarHidden:YES animated:YES];

Try to animate the y value of UINavigationBar and UIToolBar like this
[UIView beginAnimations: nil context:NULL];
[UIView setAnimationDuration:0.4];
[UIView setAnimationDelegate: self];
CGRect rect = self.navigationController.navigationBar.frame;
rect.origin.y = -40;
self.navigationController.navigationBar.frame = rect;
[UIView commitAnimations];
Hope this helps you too.
A.

In iOS 8, you can simply achieve by this:
self.navigationController.hidesBarsOnTap = YES

well you can still use the
[self.navigationController setNavigationBarHidden:YES animated:YES];
and you can stop your view from sliding up when the navigation/ toolbar shows. You can have your navigation/tool bar fade in and out over the view without sliding the view. Try this code it did work for me.
self.wantsFullScreenLayout = YES;
that is if you are currently on the view controller.

Related

Smoothly resizing navigation view when toolbar or navigation bar animates on or off screen

I'm animating a UINavigationController navigation bar and toolbar on and off screen. That works as expected -- but the view contained between them doesn't change size smoothly.
The bars animate on and off as they should, but the navigation view between them jumps from the reduced size (when both bars are visible) to the full screen size (when they're hidden).
Purely as a guess, I've tried this:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[[self navigationController] setNavigationBarHidden:YES animated:YES];
[[self navigationController] setToolbarHidden:YES];
[UIView commitAnimations];
...but it doesn't make any difference.
Is there any way to get the navigation view to change size smoothly?
I can solve the problem by using animated:NO so that everything jumps, but that looks ugly.
Thanks in advance.
What I did to create a smooth view transition:
1) In Interface Builder, the view which basically in between of the navbar and toolbar, should not automatically resize its content (eg a picture) so I unticked Autoresize Subviews flag
2) Then created the following touch handler for the hide/unhide event. The key point is using the
[UIView transitionWithView:self.view
duration:UINavigationControllerHideShowBarDuration
options:UIViewAnimationOptionCurveLinear
animations:^
{
/* Put other animation code here ;) */
}];
code snippet to add extra animation for the built-in hide/unhide animations.
Originally I tried simple: hide/unhide the two bars and let iOS resize the inner view. The result (on Simulator) was disappointing, it was not smooth. If I did only one bar hide, it did well the view resizing, but not with two bars in the code.
So here's the full touchedBegun event handler which does the trick:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
AppDelegate *app = (AppDelegate*) [[UIApplication sharedApplication] delegate];
if (blVisible) {
[app.navigationController setToolbarHidden:YES animated:YES];
[app.navigationController setNavigationBarHidden:YES animated:YES];
[UIView transitionWithView:self.view
duration:UINavigationControllerHideShowBarDuration
options:UIViewAnimationOptionCurveLinear
animations:^
{
/* Put other animation code here ;) */
self.img.frame = CGRectMake(0, 0, 320, 480);
}
completion:^(BOOL finished)
{
}];
} else {
[app.navigationController setToolbarHidden:NO animated:YES];
[app.navigationController setNavigationBarHidden:NO animated:YES];
[UIView transitionWithView:self.view
duration:UINavigationControllerHideShowBarDuration
options:UIViewAnimationOptionCurveLinear
animations:^
{
/* Put other animation code here ;) */
self.img.frame = CGRectMake(0, 0, 320, 387);
}
completion:^(BOOL finished)
{
}];
}
blVisible = !blVisible;
}
One small comment: it is smooth now, but in Simulator what I see is that iOS somehow hides/unhides the two bars not in-sync so the view resize is not perfectly timed. Pls check on device too.
If you want more perfect solution I think you have to implement the bars for your own to fully controll their hiding/unhiding effect...
Within that animation block, you could try setting the frame of your in-between view to what it should be after the bars are hidden. That should make the transition smooth.

How do I set the page curl bottom side background color/image during the transition animation?

I'm transitioning between views in my application using a UIViewAnimationOptionTransitionCurlUp transition animation. However the standard white background of the bottom side of the page curl looks ugly in my application. How do I change the background color (or image) of the 'page' backside?
I've tried without success the suggestions posted on these two pages:
How do I control the background color during the iPhone flip view animation transition?
http://adrianhosey.blogspot.com/2009/04/putting-background-behind-uiview.html
As per the suggestions in the above linked posts I've tried adding a subview to both my view and window by adding the following code to viewDidLoad: but this also did not work:
UIView *dummyView = [[UIView alloc] initWithFrame:self.view.window.frame];
dummyView.backgroundColor = [UIColor blueColor];
[self.view addSubview:dummyView];
[self.view.window addSubview:dummyView];
For reference, this is my animation code:
[UIView transitionWithView:self.view
duration:0.75
options:UIViewAnimationOptionTransitionCurlUp|UIViewAnimationCurveEaseIn
animations:^{}
completion:^ (BOOL success){
// do some stuff here
}];
Any ideas?
Put this code for animation curl up.....
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.80];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:self.detailviewcontyrollerObj animated:YES];
[UIView commitAnimations];
Hope this helps...:)
you can also try this in your appDelegate's application didFinishLaunchingWithOptionsmethod:
[window makeKeyAndVisible];
window.layer.contents = (id)[UIImage imageNamed:#"yourImageName"].CGImage;

UIView animation transition between views

I need to make an animation that will come in from the right, displaying the new view.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelay:.5f];
[UIView setAnimationDuration:0.5f];
// display view controller
[UIView commitAnimations];
What should I add here??
IF you have navigationController then use
NextViewcontroller *nextView = [NextViewcontroller alloc]initWithNibName#"NextViewcontroller"
bundle:nil];
[self.navigationController pushViewcontroller:nextView animated:YES];
[nextView release];
How about adding the view as a subView to your current view, then set its place to be outside the current visible area. After which you set your animation to change your subViews position to overlap the current view.

Fade to black within a uinavigationcontroller?

I want to fade the whole screen (including navigation bar) to black when a user presses a button on a uinavigationcontroler, before showing a new view. (i don't want to push this new view, for various reasons).
How would I achieve this?
EDIT
Thanks to Mac and Eiko, I have figured it out. Here's the code I used. Not sure if it is optimal, but it does the trick.
// this is called from a programmatically constructed button.
// change (void) to (IBAction) if linking from IB.
- (void)fadeAndShow:(id)sender
{
// blackView is a #property which has been #synthesize-d
// do I really need to alloc and init this?
blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
blackView.alpha = 0.0;
[blackView setBackgroundColor:[UIColor blackColor]];
[self.navigationController.navigationBar.superview addSubview:blackView];
[UIView beginAnimations:#"fadeAway" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDidStopSelector:#selector(showNewScreen:finished:context:)];
blackView.alpha = 1.0;
[UIView commitAnimations];
}
-(void)showNewScreen:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
// I guess you could fade in somewhere in the new view controller.
// don't know how to fade back in this view tho... viewDidAppear?
NewViewController *controller = [[NewViewController alloc] initWithNibName:#"NewView" bundle:nil];
[self.navigationController setNavigationBarHidden:YES];
controller.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:controller animated:NO];
[blackView removeFromSuperview];
[controller release];
}
Off the top of my head (I haven't actually tested the following at all):
-(IBAction) buttonClicked:(id) sender
{
[UIView beginAnimations:#"myAnimation" context:nil];
[UIView setAnimationDuration:ANIMATION_DURATION];
blackView.alpha = 1.0;
[UIView commitAnimations];
}
Create a UIView in the navigationbar's superview (which I'm assuming is window-sized) that is the same size as the window.
Set that view's backgroundColor to [UIColor blackColor], and its alpha to 0.0.
In your button handler do something like the above (assuming your new UIView is blackView and ANIMATION_DURATION is your desired animation time in seconds).
Then, add your new view on top.
EDIT: too quick for me Eiko! Also, code at the top since the ordered list seems to screw around with the code formatting - sorry the answer reads a little odd.
You can add a black coloured UIView in screen size on top of your current view, and animate its alpha from 0 to 1. When the animation is done, add your new view. You can remove the black one then. Animate from 1 to 0 for the opposite effect - going from black to the content).

Leftover Nav Bar in Landscape View

I am working to force a view into landscape mode, and have picked up all kinds of cool tips to make this happen, but am stuck on one item that is left on the screen.
I have my XIB file laid out in landscape, and in my code I create the view controller normally:
RedeemViewController *aViewController = [[RedeemViewController alloc] initWithNibName:#"RedeemViewController" bundle:nil];
aViewController.hidesBottomBarWhenPushed = YES;
aViewController.wantsFullScreenLayout = YES;
[[self navigationController] pushViewController:aViewController animated:YES];
Inside the controller viewDidLoad I complete the following:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
[[self navigationController] setNavigationBarHidden:YES animated:YES];
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
}
[UIView commitAnimations];
What I end up with is a perfectly rotated view, with a grey vertical bar on the left side (see pic).
alt text http://taxhelp.net/vert_bar.png
So to the question, how do I get rid of the bar?
Edit: I am pretty sure this is the navigation bar that is not being hidden.
This is a duplicate of another post, with some modified code, the other question was being answered with the bug.
Remove the navigation bar from Interface Builder or see if its being left behind by one of your other controllers.
I lost a few days on a similar problem because I didn't realize that one of my navbars was not being removed when another controller with a nav bar was being pushed onto another controller with a navbar. ;)