Update positionForBar for toolbar - ios

In my app I use a toolbar on the top because it lays out bar button items better for what I need, and I set the toolbars delegate to the view controller and tell it to be top attached. I also have a setting that will hide the status bar, so the issue that is happening is that when the status bar is set to hidden, and the app is closed and then re-opened, positionForBar is called but since there is no status bar, it doesn't do anything to the toolbar, so when I turn the status bar back on the app looks strange, and the toolbar is 20px down, and the status bar is showing but there is no background to the status bar, so it looks strange. positionForBar is being called still though but for some reason I need to close the app again before the toolbar will draw behind the status bar again. I have found out that if I remove the toolbar from the superview and re-add it again, it will draw behind the status bar, or i can remove positionForBar and have my own view be the background for the status bar, my old issue with this solution is that it won't be transparent (I could maybe put a 20px toolbar there though maybe?) and my problem with removing it and re-adding the view is then I will need to move a ton of my code around because remove it and re-adding it messes with constraints so I will need to fully reconstruct the entire view just for it to redraw behind the status bar. Is there a way to just refresh the view or something? I have tried setNeedsLayout and setNeedsDisplay and nothing really works for it to redraw besides removing and re-adding

Try manually setting the UIToolbar's frame:
topToolbar.frame = CGRectZero
Or updating the constraints, either will cause the UIToolbar to update its attachment.

Related

White Bar appearing at bottom of each view controller in storyboard but doesn't affect when ran

In my storyboard view these white bars appeared at the bottom of every view. I can't remember what I did when they appeared, the only thing I can think of was that I tried to add a bar button but then deleted it, so maybe that created some sort of bar. However the bar doesn't show up when running the app in the simulator, it just has a visual in the storyboard.
Does anyone know what it is / why it appeared? and also how can I get rid of it. I got rid of a few by changing the view heights and then changing them back, but when trying to do the same in the first view when I clicked the white bar they all appeared again on every view.
Also, I've noticed some are within the view and some are an extension.
This issue is caused by adding a bar button item and then removing it. The fix is pretty easy though. Go to your storyboard and select the View Controller having the issue.
You will then want to go to the Utility area on the right side of your screen. You will see Bottom Bar = Translucent Toolbar. Change that to None and you're good to go.

Attach a Segmented Control to UINavigationBar

In my App, I have a map view and I want to use a segmented control to change the map types (Standard, Hybrid, Satellite). The way I have the app set up, the status bar is hidden and it animates in, moving the navigation bar down a bit. To make sure it doesn't look awkward, I want to make it so the segmented control is attached to the navigation bar so it animates nicely as the status bar comes in. This is basically a picture of what I want to do:
So I noticed that the segmented control is inside a toolbar, so I contain mine in a toolbar as well. I've then tried adding the toolbar to the navigationBar as a subview. (self.navigationController.navigationBar). That works well accept that it can't be tapped because the navigation bar's frame doesn't enclose the extra space, so it can't receive touches. I tried making the frame of the bar bigger, and that worked, but the title and the buttons went away. Obviously there is some way to do this, and I would appreciate any help. Thanks.

Search bar partially disappears when switching views in iOS 7

We have a UISearchBar backed by a UISearchDisplayController in our app. Changing screens with the search bar hidden partway under the header causes that portion of the bar to be gone when the user returns, revealing the search bar's background. Here, I have it set to red which shows me that the search frame size and position are still correct.
Tapping anywhere inside the bar brings up the keyboard as expected. However, once the bar moves to the top of the screen, the part that was hidden stops responding to input. This blocks text selection and taps to the top of the Cancel button.
I have experimented with all of the answers in this question without success, so I think our issue is different, though likely related. Does anyone know what's going on, and how we can fix it? Thanks for your input.
If you are running on iOS 7.0 version then you need to set following property which is newly introduced in iOS 7.0 as follows
self.edgesForExtendedLayout = UIRectEdgeNone;
as by default edgesForExtendedLayout property is set to UIRectEdgeAll that means the view controllers use full-screen layout by default. And your's searchbar appeared to be rendered behind the navigation bar, starting from navigation bar offset.

Any quick solution to make a view appear behind the status bar in iOS 7?

I'm porting my app from iOS 6 to IOS 7 (there will eventually be a complete GUI redesign for iOS 7 but in the meanwhile just getting the existing GUI to display properly on iOS 7 is the goal.
I had the issue where the status bar was overlapping my GUI and so have shifted the Y origin of the view controller's view down by 20.
However my app contains a pulldown which when retracted is overlapping with the status bar. In the screenshot the red is a button which is present in the pulldown view. The grey bar is the top of the main view behind which a portion of pulldown is hiding when retracted.
I implemented the pull down as a fixed size child subview of the main view and when retracted its Y origin is a negative number thus it is effectively still displayed but off the top of the screen. When the user pulls it down I just animate the increase in the Y origin until eventually the origin is 0.
Is there some way I can make the pull down view appear beneath the status bar or some other quick solution?
Note of course I can't simply toggle the pulldown's alpha to display/hide it as it pullsdown obviously thus its appearance/disappearance is not a discreen action. I could maybe attempt to make the portion of it that is on top of the status bar invisible but as its something that is moving that seems like its going to be complicated. Is there any simple solution?
Thanks
Add another view, with a fixed position, under the status bar (with the same color of your grey bar), 20px tall and same width of the status bar, but with a z-index higher than the retracting view. This view will cover the retracting view (but not the status bar) acting as a "background" for the status bar itself. Obviously you have to adjust the Y position of the retracting view to make it tappable by the user (but under the status bar)
iOS 7 by default lets views take up the fullscreen, including the status bar. This is controlled using the UIRectEdgeAll property.
If you want the old style view, set UIRectEdgeNone for self.edgesForExtendedLayout
in viewDidLoad:
self.edgesForExtendedLayout = UIRectEdgeNone;

Why are touches not detected at top of screen with status bar hidden?

In our app, we show modal windows that take up the whole screen, and we hide the status bar at this time. However, buttons placed at the top of the screen have reduced hit areas: their tops do not detect touches. This is true of custom buttons and buttons in the navigation controller.
What is preventing detection of those touches?
FYI: I have two other windows, a HUD view and a status bar overlay, and both are hidden. I've tried putting the status bar overlay behind the main window, as well. Problem remains.
Update: This problem is caused, at least in some cases, by hiding the status bar while still having a scroll view with scrollsToTop set to YES. Although I have found a case where the problem remains even after disabling scrollsToTop for all resident scroll views. (I wrote a simple method to walk the view hierarchy to find all scroll views and report their current scrollsToTop setting.)

Resources