In the iPod app, the navigation views have the default status bar style, and the Now Playing view is in the black style. The transition between them is animated with a crossfade. I want to do that.
My first attempt:
[UIView beginAnimations:#"whatever" context:nil];
[UIView setAnimationDuration:0.5];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlack
[UIView commitAnimations];
No joy, it pops to black. Takers?
Try this instead:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:YES];
Related
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.
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;
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.
Your bounds rectangle is created with the origin at (0, -20). Change that to (0, 0) and you should be rid of the offset and have the view filling the screen.
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. ;)
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.