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. ;)
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.
So various iterations of this question seems to have been asked on this site multiple times, but none of them seem to apply to my situation. So I've got a login screen that flips to a navigation controller upon successful login. When it flips to the navigation view, the navigation bar is all the way at the top, and then shifts down once the animation is complete. This does not create an odd white space above the navigation bar, because the navigation bar is starting embedded in the status bar during the animation. I have checked that both view controllers in question have the status bar enabled, so I'm not sure what I need to do to fix this strange problem.
Here is how I am switching the views
-(void) swapToNavController
{
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
UIViewController *coming = nil;
UIViewController *going = nil;
UIViewAnimationTransition transition;
coming = eventsNavController;
going = viewController;
transition = UIViewAnimationTransitionFlipFromRight;
[UIView setAnimationTransition: transition forView:self.window cache:YES];
[coming viewWillAppear:YES];
[going viewWillDisappear:YES];
[going.view removeFromSuperview];
[self.window insertSubview: coming.view atIndex:0];
[going viewDidDisappear:YES];
[coming viewDidAppear:YES];
[UIView commitAnimations];
}
I was able to resolve this issue by switching the method I used to perform the animations as seen in this post
I'm 2 levels down on a UINavigationContoller having already pushed a few views. Now I'm looking at an image inside one of the pushed view controllers and when I tap an info button in the navigation bar, I want the sub view to flip leaving the nav bar in place. How do I get just the subview (the view that was pushed) to flip? Right now the nav bar also flips and prevents me from navigating back up my stack.
-(void)showImageInfo
{
self.imgInfoViewController = [[ImageInfoViewController alloc] initWithNibName:#"ImageInfoViewController" bundle:nil];
[self.imgInfoViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self.navigationController presentModalViewController:self.imgInfoViewController animated:YES];
}
code from UICatalog Example.... I think it will do what you are looking for. Basically you have to do some more coding to get the flip behavior.
http://developer.apple.com/iphone/library/samplecode/UICatalog/Listings/TransitionViewController_m.html#//apple_ref/doc/uid/DTS40007710-TransitionViewController_m-DontLinkElementID_34
- (IBAction)flipAction:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:kTransitionDuration];
[UIView setAnimationTransition:([self.mainView superview] ? UIViewAnimationTransitionFlipFromLeft :UIViewAnimationTransitionFlipFromRight) forView:self.containerView cache:YES];
if ([flipToView superview])
{
[self.flipToView removeFromSuperview];
[self.containerView addSubview:mainView];
}
else
{
[self.mainView removeFromSuperview];
[self.containerView addSubview:flipToView];
}
[UIView commitAnimations];
}
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).
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.