Interaction with UIView under UINavigationBar when bar is hidden? - ios

I have UINavigationBar, and UIView under it.
At navigation bar i have UIButton, when i touch button - it hide navigation bar, and my view being visible.
At my view i have button too, but when i touch it - actions does't occur(
Also i tried -
[self.navigationController.navigationBar setAlpha:0.0];
and
[self.navigationController.navigationBar setHidden:YES];
Looking like that my view doesn't have userInteraction(
What may be, or how i can show UIView over UINavigationBar?

Related

UIToolbar shadow doesn´t hide when bar position is UIBarPositionTopAttached

I have a container view with two views and a toolbar. In the ContainerViewController I have "deactivated" the shadow of the navigation bar using this code (from Apple's library):
[self.navigationController.navigationBar setShadowImage:[UIImage imageNamed:#"TransparentPixel"]];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"Pixel"] forBarMetrics:UIBarMetricsDefault];
Also I have implemented the UIToolbarDelegate and its method
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
return UIBarPositionTop; //or return UIBarPositionTopAttached;
}
But the shadow of the toolbar is still between the navigation bar and the toolbar and not underneath the toolbar, to separate the toolbar from the content.
Any ideas why the shadow doesn't change? Or how to check, if the toolbar position is position really TopAttached.
Edit:
I try to do something like described in this post: UISegmentedControl below UINavigationbar in iOS 7 without the searchbar.
As explained there, there are two shadows, the one of the navigationbar in the navigationcontroller, that is between navbar and toolbar. And the shadow of the toolbar.
I was able to deactivated the shadow of the navigationbar as described. It works also in the viewDidLoad:
But the shadow of the toolbar is in the wrong position. Using the positionForBar: method it should be in the button of the toolbar, but it stays in the top (between Navbar and Toolbar).
So I am looking for the fault, why it does not change.
You didn't specify what method you tried to change the shadow in, but I'm going to guess that you're trying to do it in viewDidLoad:
Your navigationBar does not actually exist in viewDidLoad, instead change the shadow in viewWillAppear: like this:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setShadowImage:[UIImage imageNamed:#"TransparentPixel"]];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"Pixel"] forBarMetrics:UIBarMetricsDefault];
}

UINaviagtionBar subview doesn't fade out during UIViewController "Back" transition

I have a UINavigationBar based app. I've created a custom UIView with some titles and added it as a subview to the navigation bar:
[self.navigationController.navigationBar addSubview:_navbarView];
Everything works ok until I hit the back button in the navigation bar and the UIViewController transition occurs.
The problem is that my custom view doesn't fade away like the others elements in the UINavigationBar, it just stays the same and disappears when the transition is complete.
I want it to fade away during the transition like the native elements of the UINavigationBar, is there any way to achieve this?
If you add a subview to the navigation bar, then it will just stay there; the navigation controller doesn't know to do anything special with it. You say your custom view has "some titles" - have you tried doing this instead?
self.navigationItem.titleView = _navbarView;
Then the navigation controller knows that the view should be used in place of your controller's title, and it should animate in and out.
If that doesn't work, you'll need to look at becoming the navigation controller's delegate. Since iOS7, this can get quite complex.
If you need custom navigation bar it could be a good idea to create UINavigationController with custom UINavigationBar
- (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass
in your navigation bar class you can implement
- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated
{
if (animated) {
//your_problem_view animation here
}
[super popNavigationItemAnimated];
}

How to remove UINavigationBar label.text from second UIView Controller which is coming in first View controller?

I have one label which I am showing on UINavigationBar using addSubView Property and I am getting like:
But when I am going to secondView Controller, it is looking like:
It appears on Back Button of Second Controller. So how to remove "Status" Label from second UI.
Thank You.
Don't add subviews to the navigation bar. It's not made for that.
I recommend you to read the iOS human interface guidelines and to use a UIBarButtonItem to properly add controls to the navigation bar.
In first View controller -
-(void)viewWillAppear:(BOOL)animated
{
//Add Label on UINavigationBar
[super viewWillAppear:animated];
[self.navigationController.navigationBar addSubview:navLabel];
}
-(void)viewWillDisappear:(BOOL)animated
{
// Remove label from UINavigationBar
[super viewWillDisappear:animated];
[navLabel removeFromSuperview];
}
You should tag your subview and search for it among subviews of navigation bar in your second view controller and then [subview removeFromSuperview].
You shouldn't add subviews to your navigation bar, you can use navigation items to achieve that kind of stuff. You can init a UIBarButtonItem with initWithCustomView: which has that label in it.

iOS custom shape navigation bar

I want to developer app with a custom navigation bar like in the following images:
I think that i need to subclass UINavigationBar and add button to centre of nav bar, but i don't really know how to make navigation bar look like on image. Can you please give me advice what should i do, links to any kind of documentation would be awesome!
Similar questions about navBar that doesn't helped me:
ios back button in the bar
Use custom Navigation Bar in iOS
Custom Navigation Bar in iOS 5
rogcar
EDIT:
My idea is next: make custom navigation bar height little bigger than default size, and add background image with arrow in it and with some transparency on the edges.
If you want a button (you probably do want) you can achieve it completely by subclassing UINavigationBar. You should remember that height of UINavigationBar is read-only property.
Style but not tappable:
So let's assume we subclass the navigation bar and add button there. You could do this and it will be going look great. For example:
- (void)drawRect:(CGRect)rect
{
self.backgroundColor = [UIColor lightGrayColor];
UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width/2-50, 0 , 100, 100)];
[myButton setBackgroundColor:[UIColor lightGrayColor]];
[myButton setTitle:#"Normal" forState:UIControlStateNormal];
[myButton setTitle:#"Highlighted" forState:UIControlStateHighlighted];
[self addSubview:myButton];
[self sendSubviewToBack:myButton];
}
But you will facing a problem that your button is non tapeable below UINvaigationBar. (I post an image on the bottom of the answer)
So there is clearly not a path you want to follow. Don't even try that.
Style but not tappable 2:
You may override this method in your navigation bar subclass
- (CGSize) sizeThatFits:(CGSize)size {
return CGSizeMake(custom_width, custom_height);
}
And then mask it using UIBezierPath for example
The right (tappable) way:
You have to create a view stick to your UINavigationBar. What i will do here (if you want it to every screen) is:
Make a Category of UIViewController which can draw (for example - this is easiest way) UIButton.
Style this 'UIButton' whatever you want (if you want
Pin action to 'UIButton': [btn addTarget:self action:#selector(menuShow:) forControlEvents:UIControlEventTouchUpInside];
menuShow: method should be declare in your category
You can call drawing button every time you want to redraw view controller.
As you can see there there will be two separates View: UINavigationBar and UIButton. This is allow you to set content under this little button and make it tapable.
So why just don't hide navigation bar, and use different view? Because iOS7 ;) When Apple change it in iOS7 for example then you have to rebuild your pseudo NavigationBar, with only additional view, you don't need to do anything.
You do not need to subclass UINavigationBar. Create UIView add to it UIImageView as background with image in the shape you need, add button.
Subclass UINavigationController hide UINavigationBar, add custom navigation bar.
First Hide navigation bar using -
self.navigationController.navigationBarHidden = YES;
Then create UIView with required height,height of navigationBar is 44px.Then create background image view, object of required UIButton and add all objects on created UIView as a subview.It will look like navigationBar.Thank you.
You can add your custom shaped view as titleView on the navigation bar.
Just make sure that clipsToBounds is set to NO, so it doesn't get clipped.

NavigationBar coincides with status bar when searchDisplayController is activated iOS 7

I have a tableView controller which has a searchbar added to tableHeaderView. When I click on searchBar it animates to cover the screen. However, the view behind gets adjusted and navigationBar overlaps with status bar as shown below:
It adjusts back fine, when the search is cancelled. How to hold the view at the back of searchDisplayController not to overlap the status bar?
fixed by doing: [[[parentFileViewController navigationController] navigationBar] setHidden: YES]; in searchDisplayControllerWillBeginSearch method where parentFileViewController contains the searchBar

Resources