I want to display a ViewController from the bottom over the current ViewController, with a specific height. Then I added the ability to move the ViewController up, all the way behind the StatusBar. I implemented it with a UIPresentationController. It looks like this:
And now I have a big Problem: When I set a new Value to any label, the method setNeedsLayout gets called and the view of my presented ViewController adds padding of 20px to the top. It looks like this:
My Aim is to set the new Text to labels without triggering this padding insertion. Why is it even added? I tried setting the frame and bounds of the view manually, but it didn't work. The property automaticallyAdjustsScrollViewInsets didn't help either.
After some research I found out that I just could override the prefersStatusBarHidden method. By doing this, the status bar went away. Because the dialog is modal, I needed to add myDestinationController.modalPresentationCapturesStatusBarAppearance = true to make it work.
I hope it helps some people in the future!
Related
in iOS 13 it happens that the view of UIViewcontroller that is presented as model starts from the tip of the arrow. Because of it top banners in all of my popover gets cut. Can I prevent this from happening ? I want that my UIView does not start from arrow but once arrow is finished.
To fix this issue, I opened up my view controller's XIB, selected the top-most view, and then checked "Use Safe Area Layout Guides" under the File Inspector. Then I added Auto Layout constraints (of length 0) around that view's sole subview (a UITableView).
(I also needed to update the view controller's background colour. This changed the arrow colour back to what it was in iOS 12 and before.)
Background: https://forums.developer.apple.com/thread/122703
I wonder if your contentView contains UIScrollView. If yes, please add alwaysBounceVertical = YES to your scrollView. It works in my case.
I don't know why they changed this behavior, it can be a pita to deal with it if you are not using xibs. I couldn't find anything in the docs about it.
Use the safe areas to adjust the position of your view. You can both try to extend the size of that red area, or skip the arrow completely. In this particular case you can use safeAreaInsets.top if the arrow is going to be on the top always.
I have a View inside a ScrollView inside my main View
The problem is that my scrollView have a bad default contentOffset.
His value is (0, -64) in portrait
The Apple doc says
The default value is CGPointZero.
I put this code on my controller to temporary handle it :
dispatch_async(dispatch_get_main_queue(), {
self.scrollView.setContentOffset(CGPointZero, animated:false)
})
Why my contentOffset have not the good default value ?
It's probably an issue with the view insets.
On your XIB/Storyboard for your view controller, make sure to uncheck the Adjust Scroll View Insets
or in your code add self.automaticallyAdjustsScrollViewInsets = false
Swift 4.2+
scrollView.contentInsetAdjustmentBehavior = .never
I found the explanation on this website:
http://www.codelord.net/2013/10/18/adapting-scroll-views-to-ios-7/
Handling navigation bar on top of our scroll view
The iOS 7 view of course comes with the new look where scroll views go under the navigation bar for a nice effect. One can change the scroll view’s contentInset manually to cover for the portion of it that is being overlapped at the top, but doing so manually is tedious and not fun. I was very thrilled to discover handling it should come at no cost if my ViewController has automaticallyAdjustsScrollViewInsets set to YES.
This didn’t work for me out of the box since it turns out for the magic to happen the scroll view has to be the first subview of your ViewController’s UIView. I had to reorder my subviews and then the magic started rolling.
I don't know exactly why, but the scrollbar of my tableview never reaches the end.
This is the middle of the tableview, everything looks fine
But when I reach the end
The scrollbar doesn't reach the end...
I guess my constraints are ok (I'm using autolayout), because besides the scrollbar, the tableview is well displayed.
My view controller is a UIViewController and contains only a UITableView. Here is a screenshot that sums it up :
No constraint is added by code. Do you know how could I debug this?
Thanks in advance
Edit : I have tried to delete and recreate the view controller (by copy and pasting the UITableView) the problem is still here.
Edit2 : If I change the bottom constraint to "Bottom of the view" instead of "Bottom layout guide", this works well.
The problem is that my view doesn't have a correct height, because it is supposed to go under the tabbar.
Any ideas ?
I've fixed the problem by settings the property automaticallyAdjustsScrollViewInsets to NO.
More details could be found here:
https://stackoverflow.com/a/21302259/1295537
What could be happening is you have clipping disabled, and the frame for your tableView isn't the entire height of the view.
Or, you could have contentInsets set, which changes the size of the scroll indicator as well.
For those who the above solutions don't work, try this. It makes no sense tho, but it works (In my case I needed the UITableView to behind other views, so I just added a dummy view)
https://stackoverflow.com/a/23019724/1148910
Instead of using a normal View Controller and dragging in a tableview in a storyboard (which I assume you're doing), have you considered using a Table View Controller? You shouldn't have this problem in that case (I never have). You can easily embed the Table View Controller in the Tab Bar Controller.
Hope this helps!
I'm trying to place a button over a mapview. In storyboard I have it as the last control in the view hierarchy, the map view still covers it up. I've tried adding this line in my viewDidLoad method to bring my button view to the front but it doesnt seem to work either
[self.view bringSubviewToFront:self.flagButton];
anyone have any idea why this wouldnt be working? the map view covers most of the screen, and I want to place a few buttons on top of the map, but so far can't get them to show up, they are under it every time.
I was able to do this by making my view as subview of map view.
first,
self.view = self.gmsMapView;
then,
[self.gmsMapView addSubview:_myBtnView];
I know this is an old post, but I'm answering for the sake of someone facing the same problem.
I was having the same issue, then I found a solution, and is as follows:
First, open your project and go to your StoryBoard then click on "Show Document Outline" switch that is on bottom left very small switch. After that select your "Scene" that you are having problems with then click "View". Find your MKMapView object and drag it up until you reach the first row. This will make your MKMapView object (or any other) "the first in a layer" so to speak.
I hope someone will find this helpful.
E
I was using storyboards and was not seeing the button. I had to set the MKMapView to hidden until the button was displayed and in position. Then I set the MKMapView to visible.
Here are the steps I had to take in the interface builder to get my button to show
Create a UIViewController which contains a view
Add an MKMapView and set constraints
Add UIButton in the same view as the MKMapView, set the image and text, whatever is applicable. If MKMapView disappear when you try to resize or move the button, the map view has just set its width and height to zero. Enter new values in the Size Inspector for the map view and it will resize back. Or you can move the button elsewhere off the MKMapView and then move the button back to where you want it.
The important part is to set constraints for the UIButton. I also had to set the MKMapView hidden until I got the size and placement right and then set it back to visible.
Here's how it looks in the simulator
You can't add a subview to an MKMapView via the storyboard. Add it as a sibling view instead.
Edit: Your map view should also be a subview of the root view (i.e. self.view) for this to work.
I was having similar issues and I did the following:
Made sure both the map view and the button are at the same level in the view hierarchy, I accomplished this by creating a View that both the map view and button were children of.
Made sure the button is dragged below the map view in the left gutter of the storyboard (so it is actually rendered on top).
Made sure there were valid constraints for the button.
The only thing new that hasn't already been mentioned was double-checking the constraints, and that appeared to resolve it for me. Hope that helps.
For my current project I wanted to use storyboards and autolayout instead of coding everything by hand. It has gone well so far, but my design has a section of the app where there is a tab bar and one of those tab needs to show four views. The design is to swipe between the four and so I thought to use a scroll view. After some trial and error I found that embedding a Container View in the tab allowed me to easily set up a scroll view and put a couple of view inside it, carefully aligning them using positioning to put them side by side so that each page is one child view. I'm not sure how that plays with the autolayout, and in fact I have the problem that the scroll view won't scroll past the first page position. I can drag about 1/3 of the second page into view, but it never brings that page entirely in view.
I've checked the content size and offset and all of the view positions and it all seems correct. And when I use Spark Inspector to change the scroll offset to the position of the second view/page, the app shows the right page/view and I can even scroll back to the first page. I'm a bit perplexed as to what is causing it to not scroll properly. I don't have any code to show as this is all done in storyboards, but I am wondering if anyone has any ideas as to what is wrong?
Alternately, does anyone have an idea for how to use autolayout and storyboards to set up swiping four adjacent views in a tab? I suspect there are ways to do it. I can think of ways to do it in code, but I'm trying to avoid doing it that way.
EDIT: I set the scroll view delegate to the view controller around it and checked the values of contentSize on scrollViewWillBeginDragging and scrollViewDidScroll. It is always set to {0,0} even after I force set it on viewDidLoad. So I tried setting it every time scrollViewWillBeginDragging is called, which seems work, but I don't understand why this happens and it doesn't smell right. Is there some autolayout constraint that might account for this? Does something cause contentSize get set to {0,0} during the layout process?
For lack of any other answer, I'll use my unsatisfying solution as an answer in the hopes that helps someone else in the future:
I set the scroll view delegate to the view controller around it and checked the values of contentSize on scrollViewWillBeginDragging and scrollViewDidScroll. It is always set to {0,0} even after I force set it on viewDidLoad. So I tried setting it every time scrollViewWillBeginDragging is called, which seems to work.
I'd love to know why the contentSize is being reset if anyone finds out!