Anyone know how to remove unwanted animation from navigation bar? Screenshots - ios

I have a view controller which proceeds via a button to a table view controller.
In the view controller, the navigation bar is totally translucent (As you can see in the screen shot below). On the table view controller, the navigation bar is set to white.
My problem is, when I press 'back' in the table view and return to the view controller, the white navigation bar is carried over for a moment (see top image) before disappearing in an ugly animation.
Extra Navigation bar space:
How I want it to always look:
I have tried pretty much everything I can think of, all my code relating to the navigation bars translucency is in viewDidAppear, so why is this happening!?
Someone please tell me what I'm doing wrong! This is making me crazy!

In the tableviewcontroller set:
- (void)viewWillDisappear:(BOOL)animated {
// put the code for the uinavigation bar styling here.
}

You can do some thing like this have a custom back button below is the code
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(2, 1, 29, 29);
[backButton setBackgroundImage:[UIImage imageNamed:#"back_button"] forState:UIControlStateNormal];
[backButton addTarget:self action:#selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
backButton.adjustsImageWhenHighlighted = NO
item.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
where item is instance of UINavigationItem
and in selector of back button
-(void)backButtonClicked:(id)sender {
[self.navigationBar popNavigationItemAnimated:NO];
}
by doing this the navigation bar will pop the item but without animation.

Related

How to make a navigation back button just the complete same style with system?

I tried to make a navigation back button which has the same complete style as system, but no matter how I adjust it still had a little difference.
system
custom
You can see no matter the arrow or the word (返回 BACK) both have some difference.
Here is the code I tried and I got the arrow image from here.
UIImage *sourceImage = [UIImage imageNamed:#"nav-back-btn"];
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypePlain];
[backBtn setImage:sourceImage forState:UIControlStateNormal];
[backBtn setTitle:#" 返回" forState:UIControlStateNormal];
[backBtn addTarget:self action:#selector(goPreviosPage) forControlEvents:UIControlEventTouchUpInside];
backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
backBtn.transform = CGAffineTransformScale(CGAffineTransformMakeTranslation(-8, 0), 1.1, 1.1);
Use the default UINavigationcontroller strategy.
Add a navigation controller and its view controllers.
Give both view controller navigation title. self.navigationItem.title in view did load.
Just pushing the navigation controller will default have a back button and the title of the previous view controller to it with same system stle.
Do not set any custom leftbarbutton item as this may overide the UINAvigationcontroller to show the default back button.
Hope this help.

How to make bar button items have 2 lines of text?

I try to follow this one, but it doesn't work.
How can we put two line in UIBarButtonItem in Navigation Bar
I don't know why the button view I created and assigned to the bar button item cannot display at all?
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.titleLabel.numberOfLines = 0;
[button1 setTitle:NSLocalizedString(#"REQUEST\nEQUIPMENT", nil) forState:UIControlStateNormal];
[button1 sizeToFit];
self.barButton = [[UIBarButtonItem alloc] initWithCustomView:button1];
Or is there any better way to have more than 1 line of text in the UIBarButtonItem?
The problem is that you are making a bar button item but you are never putting it into the interface. Setting self.barButtonItem doesn't put the bar button item into the interface; it just retains the bar button item. This has nothing at all to do with the "two-line" question. You cannot make any bar button item appear by doing what you're doing.
A bar button item appears when, say, you are a view controller in a navigation interface and you set self.navigationItem.rightBarButtonItem to your bar button item. But you are not doing that.

TabBarController does not hide the subviews in its view when it hides bottom bar on push

I am trying to make an app that is based on a TabBarController which has a custom button in the middle of the tabbar that is like the one in Instagram and other apps alike.
The reason I know it will be a custom button is that when user presses the button he/she should not expect a 'view controllers' segue behavior but a presented view controller. As to my research by far, it is hard to customize a tab bar item to do anything other than switching to another view controllers owned by the tab bar.
Assuming I was right about the button having to be custom (if you know how to add a bar button item onto a tab bar and has it present a vc instead of switching to a vc, please also include it in your answer), I added a custom button to the view of the tab bar controller:
- (void)addPostButton {
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
button.frame = CGRectMake(0.0, 0.0, 55, 55);
[button setImage:[UIImage imageNamed:#"post.png"] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor colorWithRed:32.0/255.0 green:35.0/255.0 blue:44.0/255.0 alpha:1]];
[button.layer setCornerRadius:button.frame.size.height / 2];
[button.layer setBorderColor:[UIColor whiteColor].CGColor];
[button.layer setBorderWidth:1.0f];
[button addTarget:self action:#selector(addPost) forControlEvents:UIControlEventTouchUpInside];
CGFloat heightDifference = 60 - self.tabBar.frame.size.height;
if (heightDifference < 0)
button.center = self.tabBar.center;
else
{
CGPoint center = self.tabBar.center;
center.y = center.y - heightDifference/2.0-5;
button.center = center;
}
[self.tabBar addSubview:button];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self addPostButton];
}
my storyboard is currently constructed as: --root--> tab bar controller --view controllers--> navigation controller --root--> view controller. Now I am trying to make the navigation controller push a view and would like to hide the tab bar in the pushed view. I checked 'hides bottom bar on push', which worked fine, EXCEPT the added subview is still there.
Apparently, 'hidesBottomBarOnPush' only hides tabbarcontroller.tabbar but not other subviews tabbarcontroller.view holds.
I also tried adding the custom button to tabbarcontroller.tabbar but nothing shows up. So it seemed that I had to add the button to the its view, not its tab bar.And When I pop the vc I just pushed, the added button is beneath the tab bar instead of right above it. Something wrong with the tabbarcontroller's view hierarchy.
If you know any solution to either add a custom button to tabbarcontroller.tabbar, or, hide the tabbarcontroller.view's subviews in an elegant way, I would greatly appreciate it.
This likely is happening because you've added the subview to the tab bar controller, not the tab bar itself. There are several ways to address this depending on how you've added the button.

How to create Navigation bar with back button on it?

I am very new to iOS App Development.
In my app I am trying to navigate from second view to first view using navigation bar back button, but while drag and drop the navigation bar in the view I am just able to get the bar with title.
I am really worried and I am not sure what I am doing wrong? I am using Xcode 4.3. and storyboard to design the view.
What i am getting now
Looking for
Thanks for your help guys
Xcode handles this for you.
Highlight your first controller. Go to the menu bar and click Embed In > Navigation Controller. Now using UIButton or something, control-click and drag from your first view controller's button to your second view controller and make it a Push segue. The back button won't appear, but if you run it, it will be there.
So you should have 3 views in storyboard. The Navigation Controller, your first view controller, and your second view controller.
Here is one way to do it using code.
if you want to get a plainButton in the navigation like the iphone`s backButton (only one view), you must add image, i think there is no other way.Of course , if you have 2 or more viewcontrollers , you will use navigationItem.backBarButtonItem without add image .But the first viewcontroller do not have the backButton.
the code like this:
navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UINavigationItem *navigationItem = [[[UINavigationItem alloc] initWithTitle:#"Detail"] autorelease];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
[button setImage:[UIImage imageNamed:#"plain.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]
initWithCustomView:button];
navigationItem.leftBarButtonItem = buttonItem;
[buttonItem release];
[button release];
[navigationBar pushNavigationItem:navigationItem animated:NO];
[self.view addSubview:navigationBar];

iOS Custom Back Button without calling method in every View Controller

I would like a more elegant solution to changing the back button for an Application's Navigation Bar. All the answers I've seen only talk about customizing a button and then adding at least one line of code to each View Controller for the new button to display.
I have a category where I modify the Navigation Bar's background and Title. It's a category of UINavigationBar. The category calls willMoveToWindow: to call methods each time a new view is pushed on the Navigation Controller.
So here's how the code to create a new button would look:
- (void)applyCustomButton{
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 26, 26)];
[backButton setImage:[UIImage imageNamed:#"arrow-left"] forState:UIControlStateNormal];
[backButton setShowsTouchWhenHighlighted:TRUE];
[backButton addTarget:self action:#selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
[self.navigationItem setLeftBarButtonItem:barButtonItem];
}
The problem here is that self.navigationItem won't work here. I don't want to bore you with all the things I tried categorizing, but that property only works on View Controllers (I think)?
You don't have to give me a solution for the code above, maybe you have a better way of customizing the Back Button on the Navigation Bar without having to write code on every View Controller Class I have. I just hate repetition because maintaining code like that sucks.
Thanks in advance.

Resources