I am trying to add a UIImageView
to the back of a navigation bar.
The reason is because I want to create a UITableView
whose navigation bar is actually a picture (with back button on the left) but I want the picture to scroll with the tableview and when the picture is fully scrolled out. The navigation bar is shown as per normal.
My solution to this problem:
Add a UIImageView
to the top of the UITableView
and make the navigation bar transparent. Set a contentOffset
for the UITableView
which is a subclass of UIScrollView
so that when the view is presented, it looks like the picture is filling the navigation status bar. Problem:
If I scroll up, instead of bouncing back, the transparent status bar is shown (with a color of the background as it is transparent). Possible way to solve this new problem:
I was thinking of trying to limit the ScrollView
size to get around with problem but failed.
So I feel is it possible to add the UIImageView
to the "back" of the navigation bar so that it is there without any offset? Since that way, my life will be much easier.
Any suggestions on solving this or another new approach to get the same UI/effect?
Related question.
I would do this by adding either a table header or cell at the top of the table which contains your image.
Create the table view so that it extends all the way to the top of the screen. Extend Under Top Bars option. I have not done this with a UITableViewController
but I have done this with a UITableView
embedded inside a UIViewController
's view with the top constraint set to 0 for the view rather than the top layout guide.
Now when you run this your table will fill the whole screen and the top header or cell will be at the top showing your picture.
When you scroll you can either use the UIScrollViewDelegate
to detect the movement or implement tableView:didEndDisplayingCell:forRowAtIndexPath:
I'm not 100% sure when you want the navigation bar to go non clear. If its when the image goes off screen then didEndDisplayingCell should be good. If its when the cell bottom passed under the bottom of the navigation bar then scroll view might be your only option.
This will also bounce as you expect when you pull down and it should snap back to the top.
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.