iOS > Changing Navigation Bar zPosition and UIImageView - ios

I want to place image over navigation bar, but partially on it an partially on content view. So I set UINavigationBar.layer.zPostion to -1 and it works perfectly well especially on iPhones. But I also have background UIImageView with UIImage and it should be placed beneath navigation bar. So I tried to set it zPosition to -2 or -10 it doesn't work and it is seen through navigation bar somehow. I even tried to place another UIView above Background UIImageView and beneath NavigationBar to be able to mask/hide this image and have colour like navigation bar. But it doesn't work. If i use UIView with some color instead of ImageView then it works correctly.

I've forgotten to add
clipToBounds = true
This solves the problem

Related

Is there a way for a logo image to have a greater height than the navigation bar and still be fully visible?

I have a situation where I need to create something like this:
The problem is that the logo is higher than the navigation bar is, and I want this all to be a part of the navigation bar. I’ve tried “pushing” the logo from the top, but it doesn’t really work. If I increase the height of the logo image, it just cuts it off where the navigation bar ends.
Also, the back button should be aligned to the top of the logo image.
Currently I am using a custom view for this and hiding the navigation bar, which I hate, so if anyone has any advice/suggestions it would be greatly appreciated!
Thanks!
Try setting title view's clip to bounds and masks to bounds to false by setting
self.navigationItem.titleView?.clipsToBounds = false
self.navigationItem.titleView?.layer.masksToBounds = false

Set navigationbar size according to background image

I have set an backgroundImage for my navigationbar. This works fine. But I would like to have the navigationbar height to be adjusted to the background image. At the moment the width of the background images is also not set according to the screen size.
I tried setting the height of the navigationbar like described here. This shows a bigger navigationbar for like a second but then it shrinks to its default size again.
Does anyone know how to achieve what I want? Here is an example of what I want to achieve: image
Apple Documentation:
It is permissible to customize the appearance of the navigation bar
using the methods and properties of the UINavigationBar class but you
must never change its frame, bounds, or alpha values or modify its
view hierarchy directly.
To achieve the effect seen in the image you tagged, they are most likely using a collection view to layout their data and that image is part of the collection view's header. They made the navigation bar background color clear, but the image is definitely not part of the navigation bar itself.
Apple recommends to never change the frame of a navigation bar manually because it messes with the layout code of its subviews and animation methods.
You could either subclass the navigation bar and attempt to create something similar, or go the easier route and make the navigation bar clear (UIColor(white: 0, alpha: 1) not .clear otherwise it might show up incorrectly) and have an underlying view display the image (e.x. a collection view whos header extends to the top of the view controller).
This will allow you to adjust the image height and width freely without subclassing the navigation bar, and creating potential bugs.
You can make custom NavigationBar class.
It can be help you
https://developer.apple.com/library/archive/samplecode/NavBar/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007418-Intro-DontLinkElementID_2

UIView overlapping with tab bar elements iOS

I made a view for a switch view. Now I already had tabbed menu buttons in it. The problem is the subview for the switch view seems to be overlapping with the tab bar icons at the bottom. Please help.
i think thats because your tabBar is set to translucent. set it to non-translucent from storyboard or programatically.
self.tabBarController.tabBar.translucent = false
You should have a constraint that sets the vertical space between your subview and your tabbar.
Also, check that your layout respects the iPhone X Safe Area (https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/), from your image it seems that your elements overlap the safe area at the bottom.

Statusbar is transparent while navigationbar is not

I'm developing an iOS app with a table view. The navigationbar in the app has an gradient image as a background.
However, as you can see from the picture, while the navigationbar itself is opaque, the statusbar is semi transparent. The content of the tableview is shown through the statusbar when scrolling, while the navigationbar itself is opaque.
I've tried to set the Translucent-property of the navigationbar to false. This makes the statusbar opaque, but it messes up my constraints, so I cannot use it.
Any idea how to fix this?

Embed a UIImageView in a bar widget either at the top or bottom of the screen

The navigation bar can take a UIImageView via the titleView property,
for example
self.navigationItem.titleView, and the The UIImageView can be animated.
Unfortunately, as per the documentation "Custom title views are centered on the navigation bar and may be resized to fit". This resizing makes it unsuitable for me.
My goal is to animate a UIImageView in something like a navigation bar, tab bar or toolbar. In other words I want to animate UIImageView in a bar that is always visible in a view.
How would I do this (using swift)?
A possible solution is to create a UIBarButtonItem with a UIImageView in the constructor and set the left or right button in the navigator bar to the animate button item.

Resources