I have a uitableview inside and uiview which is being presented in a navigation view (so it has a navigation menu). Under the navigation menu I have a uitoolbar appearing when the view loads and disappearing when the load is poped from the navigation stack.
The issue I am having with this is that when I animate this view onto the stack with normal animation transition right to left, the tableview dose not do this it just appears quickly before the view is finishe sliding into view. Then when you select the back button and the view begins to animate from left to right it dissipears before the end of the animation again.
I would like to know how to get this toolbar to animate with the rest of the view, right to left, left to right etc instead off appearing over the sliding effect abnormally.
This is how I call and dissmiss the toolbar at the moment.
- (void) viewWillAppear:(BOOL)animated
{
[self.navigationController setToolbarHidden:NO animated:NO];
[self.navigationController.toolbar setFrame:CGRectMake(0, 60, 320, 30)];
self.navigationController.toolbar.tintColor = [UIColor darkGrayColor];
[SeriesTableView setFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height)];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setToolbarHidden:YES animated:NO];
[super viewWillDisappear:animated];
}
which is pretty much the standard way of doing things.
Any help would be greatly appreciated.
The toolbar property of the navigation controller is already onscreen, but is hidden from view. If you want a toolbar to animate on and off with a certain view, add the toolbar to that view. Then the toolbar will animate on and off as part of the view.
Related
I'm using UINavigationController and I have a UIView added to self.window
UIView *myView = [[UIView alloc] init];
myView.frame=CGRectMake(0,20,320,100);//20 is to position view under status bar
[[[self.window subviews] objectAtIndex:0] addSubview:myView];
This is done in AppDelegate.m file.
And this way myView covers up the navigation bar completely.
However, when the screen orientation changes, somehow the navigation bar is brought to the very front (just like what bringSubViewToFront does) and is on top of myView (a portion of view is covered up by navigation bar).
Does anyone know why this happened? Is there a way I can keep myView on top of everything?
If you don't want to show the navigation bar, just hide it:
self.navigationController.navigationBarHidden = YES;
or:
[self.navigationController setNavigationBarHidden:YES animated:YES];
if you want to animate the change from not hidden to hidden.
You can also adjust the "z" coordinate for stuff on the screen
[aview sendSubviewToBack:asubview];
and
[aview sendSubviewToFront:asubview];
I'm working at a simple view-based iPhone application.
From the main screen of the App you can navigate to 4 different views.
One of these views consists of a tab bar.
Because this is not the normal approach I used a workaround without a UITabController.
To accomplish this I made use of this topic:
https://discussions.apple.com/thread/2099944?start=0&tstart=0
And this example code:
http://pymbian.svn.sourceforge.net/svnroot/pymbian/stuff/testtab_raynewbie/Classes/
With some small modifications this works.
Only I have one last bug when I want to return to the home view from the tabbed view, the tab bar stays in the bottom of the screen.
I tried several approaches described here.
myTabBar.hidden = YES
hidesBottomBarWhenPushed = YES
But none seem to work....
I think the problem is somewhere in the strange structure of views UI controllers. Because now the structure looks like this.
MainViewController
- ViewController with TabBar
- tab1viewcontroller
- tab2viewcontroller
- other viewcontrollers
And going back to the main view is done in the tab1viewcontroller where I can't do anything to the TabBar. In all the other views I go back with this code:
-(IBAction) BackAction:(id)sender {
mainControllerView = [[MainControllerView alloc] initWithNibName:#"MainControllerView" bundle:nil];
[self.view addSubview:mainControllerView.view];
[mainControllerView.view release];
}
Anyone an idea?
You need to hide the tab bar when pushed from previous view.
LoginViewController *loginViewObj =[[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
loginViewObj.hidesBottomBarWhenPushed=YES;
LoginViewController is the view to be pushed where tab bar is not required. :)
Try following code in view-controller where you want to hide tabbar
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[self.tabBarController.view setFrame:CGRectMake(0, 0, 320, 560)];
}
and
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:YES];
[self.tabBarController.view setFrame:CGRectMake(0, 0, 320, 480)];
}
I have a navigation view controller and I want a subview to slide on top of it when a button in the parent view is clicked. Now, the thing is when I do this:
[parentView addSubview:slideView];
[UIView beginAnimations]
//setting the frame for sliding
[UIView CommitAnimations]
the sliding view goes under the navigation bar after sliding. I would like it to slide on top of the navigation bar of the parent view. How do I achieve this?
Essentially, all I am trying to do is: replicate the iPhone Add Contact application with the only difference being; unlike me, they don't have a navigation controller on the parentView but just a navigation bar with a system add button.
Anyone!!
Hows about using a Modal View Controller....
UsernamePasswordViewController *usernamePasswordView = [[UsernamePasswordViewController alloc] initWithNibName:#"UsernamePassword" bundle:[NSBundle mainBundle]];
[self.navigationController presentModalViewController:usernamePasswordView animated:YES];
[usernamePasswordView release];
This will slide upwards by default over anything
How about something like:
[parentView addSubview:slideView];
[parentView bringSubviewToFront:slideView];
// etc
In the iPhone maps app there's a toolbar at the bottom of the map view (it contains the Search/Directions segment control and others). When moving from the map view by clicking on a callout, the toolbar slides out with the map view, leaving the next view (a table controller) with no toolbar.
I've tried to do the same thing with [self.navigationController setToolbarHidden:YES animated:YES] in the second view controller, but this gives a strange toolbar sliding down animation, while the map view is sliding to the left.
Using [self.navigationController setToolbarHidden:YES] in viewDidLoad also causes a bad effect (it makes the toolbar disappear the moment the push animation starts, leaving an ugly white space).
I'm assuming the answer to this is to use a nib file, but I'd prefer to do it programatically (if possible).
How can I get the toolbar to "stick" to the map view and slide out with it when I push a new view controller? Thanks.
Gourmet Haus Staudt http://img.skitch.com/20100518-xfubyriig48d3ckaemjg2ay8q.jpg
It turns out the answer is to create the toolbar directly and add it to the view yourself. This is in the code for a UIViewController with a UINavigationController. The frame coordinates can change according to what is on screen.
- (void)viewDidLoad
{
// Add a toolbar to the view
CGRect toolbarFrame = CGRectMake(0, 372, 320, 44);
UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];
UIBarButtonItem *compassButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"compass.png"]
style:UIBarButtonItemStyleBordered
target:self
action:#selector(zoomToCurrentLocation)];
compassButton.width = 30.0f; // make the button a square shape
[myToolbar setItems:[NSArray arrayWithObject:compassButton] animated:NO];
[compassButton release];
[self.view addSubview:myToolbar];
[super viewDidLoad];
}
I was around this for a day once. Really dont get the programatically answer, but the best way to views to behave correctly, is to do the interface in the interface builder. If you set items for a toolbar in your code like:
[self.navigationController setToolbarItems: control1, control2,..., nil] animated: NO];
with my little experience, I can say that you are saying to the entire application to have a toolbar present when you push new views unless you hide it (or you are using a tabBar), but hiding it you get those unwanted effects.
You can try this:
[self.navigationController setToolbarHidden:YES animated:YES];
in your first controller - (void)viewWillDisappear:(BOOL)animated method,
and setting hidden to NO in - (void)viewWillAppear:(BOOL)animated method in the first controller too.
Hope this helps.
PS: And if you get the programatically answer, let me know! =P
Override the second view controller's -viewWillAppear: method to hide the toolbar.
I have seen the post for How to switch views by buttons on iPhone? but this doesn't answer how to switch back and forth between views with buttons. The person that asked the question settled on the answer that they could switch between views with uinavigationcontroller.
I put the following code in an ibaction that kicks off when a button is pressed in the primary view.
PhoneNumberViewController *phoneNumberViewController1 = [[PhoneNumberViewController alloc] initWithNibName:#"PhoneNumberView2" bundle:nil];
self.phoneNumberViewController = phoneNumberViewController1;
[self.view removeFromSuperview];
[self.view insertSubview: phoneNumberViewController1.view atIndex:0];
When this code executes the whole view just goes blank. If I omit the removefromsuperview portion then the view disappears behind my button but the button still remains. I'm not sure if this is the right way to switch between buttons but if anyone knows how to do this please help. Also if anyone knows about any example projects that switch between views with buttons let me know.
Thanks a million!
You removed the view controller's view from it's superview and then added a subview to it. The view hierarchy is broken at the view controller's superview (likely your window). That is why you are getting a blank screen.
You'd likely want to keep a reference around to the original view and then swap it out to the new view by setting the view controller's view to the new view.
// origView is an instance variable/IBOutlet to your original view.
- (IBAction)switchToPhoneView:(id)sender {
if (origView == nil)
origView = self.view;
self.view = phoneViewController.view;
}
- (IBAction)switchToOriginalView:(id)sender {
self.view = origView;
}
The technique I usually use involves creating a superview class which contains a toolbar at the bottom, and a content view UIView class filling the rest of the screen.
I then add subviews to the content view to change the views based on button clicks. This approach makes it so the toolbar on the same is constant across all views. I start by defining a helper function like this:
-(void) clearContentView {
//helper to clear content view
for (UIView *view in [self.contentView subviews]){
[view removeFromSuperview];
}
}
My IBAction then looks like this:
-(IBAction) buttonClicked{
self.title = #"Images"; //change title of view
[self clearContentView]; //clear content view
[self.contentView addSubview:self.imagesViewController.view]; //add new view
[self.imagesViewController viewWillAppear:YES]; //make sure new view is updated
[self enableButtons]; //enable all other buttons on toolbar
self.imagesButton.enabled = NO; //disable currently selected button
}