Animating UINavigationBar - objective-c

I want to slide the right button and the title in and out (instead of having things just appear and disappear). How can I go about doing this?

Instead of using property setter syntax, i.e. self.navigationController.navigationBarHidden = NO, use the method setter to specify an animated parameter:
[self.navigationController setNavigationBarHidden:NO animated:YES];
This should achieve what you want.

You can (sort of) animate the title by using a custom view for UINavigationItem's titleView property and doing the animation yourself. As for the right button, you can't animate it without completely rewriting UINavigationBar (not recommended).

Related

scrolling a scrollView inside of a textView delegate

I have a UIScrollView and contextView. I add UITextViews to it and set the delegate to self so that I can use the textViewShouldBeginEditing method. The textViewShouldBeginEditing is inside the same ViewController.m file, so the VC should be the delegate.
The textViewShouldBeginEditing method gets called and I want to check if the keyboard is blocking the textView and scroll it up if it's being blocked.
I want to call:
[scrollView setContentOffset:CGPointMake(x, y) animated:YES];
However scrollView is not seen in textViewShouldBeginEditing.
I've seen where KVO can be used, but I want to use the delegate methods.
How can I gain access to the scrollView that the textView is on?
You can use IQKeyboardManager. Just drag and drop library to your project and eveerything will managage itself. here is the github link for that. IQKeyboardManager. Hope this will help you.

Objective C / UIBackBarButtonItem Why can't change view

I've ran into an interesting and strange question while messing around with a project.
After spending like 3 hours doing it, I found out you can't change the view of the UIBackBarButtonItem, only the UILeftBarButtonItem, so if I want to implement a custom back button, I hide the UIBackButtonItem and display a UILeftBarButtonItem which does the popping.
Now I find it odd, that you can't change the UIBackBarButtonItem's view, but you can change the UILeftBarButtonItem and the UIRightBarButtonItem's views.
Can someone explain me why would Apple do this?
Actually, you can. Use UIBarButtonItem's instance method setBackButtonBackgroundImage:forState:barMetrics:.
So if you want to change the background image for all your back buttons, your code should like something like:
UIImage *backButtonBgImageNormal = [[UIImage imageNamed:#"back_button_bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 15, 5, 5);];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonBgImageNormal forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Use delegate method of UINavigationController, such like
#pragma mark -
#pragma mark - UINavigationController Delegate Methods
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//// customize you own stuff here;
UINavigationBar *morenavbar = navigationController.navigationBar;
UINavigationItem *morenavitem = morenavbar.topItem;
morenavitem.rightBarButtonItem.tintColor = [UIColor blackColor];
}
I think I have a comprehensive solution for you.
1) From experience, it's just best to not bow to limitations of BarButtonItems. I suggest you create a simple UIButton, customise it to your liking. maybe add an action to its touch events..brand it with custom background and title colors...etc.. keep a reference to this button, maybe as a property.
2) Then, you create an instance of UIBarButtonItem using the UIBarButtonItem initializer -initWithCustomView, you sneak in the UIButton instance as this custom view in the init and have complete control over it.
3) Finally, you just do this.
self.navigationItem.LeftBarButtonItems = #[ourUIBarButtonItem].
The navigation bar has an Array property "leftBarButtonItems" for series of left buttons, and rightBarbuttonItems for the right side. Just replace this with your own array, containing the UIbarButtonItem, that containing your button, and you having a reference to your button.
And now you can completely control you button that is properly in the navigation bar.
NOTE! - Once you provide such a leftBarButtonItem, the stock Apple BackButton is gone.

Xcode Adding Subview on entire screen above everything

I want to use addSubview method to add new view on my screen. However, new view must also include navigation bar etc. which means it should include entire screen. What should i do?
Whenever i try to addSubview it always shows new view under navigation bar.
I don't want to use pushViewController or presentModelViewController because new added view will be low opacity and i can see background but i do not want to interact with background objects like bar buttons table etc.
Sorry for english, i hope, i clearly told what problem is.
Just set the frame property of the view you add before, and set it with screen bounds.
[myView setFrame:[[UIScreen mainScreen] bounds];
[self.navigationController.view addSubview:myView];
If you want to disable interaction with the navigation bar :
[self.navigationController.navigationBar setUserInteractionEnabled:NO];
You could take a look at adding another UIWindow above your root window.
when I tried doing the navigationController.view addSubview, it wouldn't cover my tab bar so I did the following with my app delegate's window:
[self.window addSubview:myView];
if you need access to your appDelegate from another class, you'd just import your application delegate and call it from that.

How to change the UINavigationVIewController when using presentModalViewController

How do I set the modalViewControll to a particular size?
UINavigationController *NC = (More stuff);
[self presentModelViewController:NC]...;
that code presents my UIViewController as a full screen. I want to to be a smaller window size is that possible or do I need to do a popovercontroller?
If you want something other than full screen you can look at setting the modalPresentationStyle property on the UINavigationController you're about to display.
NC.modalPresentationStyle = UIModalPresentationFormSheet;
Look at the documentation to see what styles are available. If you need something different than those styles then you'll have to do it all yourself. If you use a UIPopoverController you have to be prepared for the user to dismiss your popover by simply tapping elsewhere on the screen.
Check out the modalPresentationStyle property of UIViewController.

Change the background color of "More" view controller

Is it possible to use an image or otherwise change the background color of cells in the "More" navigation controller of a UITabBarController?
Neither of those links are the answer to this question. It seems Malakim is referring to the MoreViewController of the UITabBarController, and not wanting to change the tabbar colors, but the cells that makeup the MoreViewController's tableView.
The answer is pretty easy. You can reference the moreViewController property of your tabBarController which would give you a reference to an instance of a UIMoreNavigationController.
UINavigationController* moreNavController = myTabController.moreViewController;
With this navigation controller you then want the root view controller's view, because this is what is holding your tableView. In fact, the root view controller is a UITableViewController, and accessing it's view grabs the tableView directly!
UITableView* moreView = ((UIViewController*)[moreNavController.viewControllers objectAtIndex:0]).view; //might need to cast here to suppress warnings
and thar ye go, moreView has a reference to hee tableView you are interested in. You could then delve further by using moreView.subviews or just make an ugly background color change like moreView.backgroundColor = [UIColor uglyColor];
The method given by Steve works fine but it was giving me warning when i try to set the view of moreNavController to a table view.
warning: incompatible Objective-C types initializing 'struct UIView *', expected 'struct UITableView *'
So inorder to remove the warnings i tried the below code and it works, not sure it is the proper way
UINavigationController* moreNavController = self.tabBarController.moreNavigationController;
UIViewController* moreViewController = [moreNavController.viewControllers objectAtIndex:0];
moreViewController.view.backgroundColor = [UIColor redColor];