After I added an UIView into one of my UIViewController I noticed SafeArea size is shortened from bottom about 40 and when I select the UIViewController it applies the effect all other UIViewControllers. When I click any other UIViewController, all displays back the SafeArea to its original size excluding the UIView added.
I deleted the UIView I added and see if it going to fix the issue but it did not.
More info about setup: UIViewController's UIViews are separated into three parts. Header-Content-Footer. All of their items has UIStackViews. I added the UIView into Content view.
When I run simulator I don't see any gap in the bottom, it looks as I intended.
Please let me know, if you need any more information/clarification.
EDIT: I noticed I have two SafeArea inside the UIViewController. Do not how this happened and how to remove one created under Content UIView.
EDIT 2: Here is the photo of the duplicate SafeArea in the StoryBoard.
I created another UIViewController and copied the content needed there.
Related
I have a problem where the frame/layer is shown correctly on iPhone, but not on iPad and iPhone X. Only after going to another view and back to that UIViewController it is shown correctly.
I have a 3 UIViews in a vertical StackView. The first top 2 are shown correctly. But the third is not. The third UIView contains a containerView and in it there is a TableView. Through the view debugger I can see that the containerView and the tableView have the correct frame, but it looks like the parent UIView is not redrawn correctly.
Here is a screenshot of the view debugger from the front of that UIView. The UIView with the red background is the one displayed incorrect (correct after going away and back to that UIViewController).
UIView with red background incorrect (Frame is correct, but displayed wrong). The subviews have the correct frame. I set a backgroundcolor to those subviews and these are redrawn correctly
Here the same view from the back:
UIView in question from behind
I tried .setNeedsDisplay., .setNeedsLayout, followed by .setLayoutIfNeeded. Running those in main thread, but didn't got success so far.
I am using Swift 4 and iOS 11. As I said this is in a vertical StackView. The first 2 UIViews have a height constraint, this one, has no constraint as it should fill the rest.
Any help appreciated!
The problem was solved for iPad and iPhone X, removing the shadow layer on the view that was drawn incorrectly.
I have designed a UIView where there's an UIImage at the top and under it there's an UILabel. Both of them are populated by JSON and sometimes there won't be an image to load so I want that when this happen, the rest of the stuff in my UIViewController move up so that the space in the picture doesn't exist.
And, actually my image isn't appearing anyway, this is my code:
self.imagen.kf_setImageWithURL(NSURL(string: "http://elpenitente.playcofrade.com/img/upload/\(idfoto)")!)
If you have a scroll view on your screen: Unchecking adjust scroll view insets in the inspector may solve your issue.
If not you probably have size constraints that your not noticing. Check the different screen configurations.
This should be a very basic question, but I have tried a lot of things and it isn't working. :/
I have a single view application which consists of a single, full-screen custom view. I had my view class set on the main view of the view controller, but the status bar was always overlaid on my view.
Apple says to fix this, constrain your view to the top layout guide, but that requires I move my view to be a child of the main view. So I moved it, but now I can't set up constraints to simply make my view fill 100% of vertical and horizontal space.
I have tried doing it in code, using constraints, stacked views, anything I can find, but to no avail.
So, the hopefully simple question is, how can I make a single UIView child of the main view of a view controller size to fill the container and account for the status bar? The UIView is a custom class, so if code is needed I can do that.
I have tried overriding the intrinsic and size that fits methods, but they created terrible results.
You can do this programmatically:
let childView: UIViewCustom = UIViewCustom()
childView.frame = rootView.frame
childView.bounds = rootView.bounds
rootView.addSubview(childView)
Or via IB:
first select your childView, then click on the pin button in the low-right corner of XCode, disable Constrain to margins, then click on each red bar and set to zero the constrain. Finally click on Add 4 Constraints
Hope it helps.
try this:
0.Assume that you have a custom class just for View (not ViewController) named AAA.
in Main.storyboard, drag a "View" from Object Library to your ViewController. Call it ViewB.
2.set the viewB layout and constrains
3.select the viewB and go to its identify inspector(3rd small button on the right panel)
4.in the class section: write it as: AAA
Hope this will help you.
I am working on a Swift iOS8/9 project and using Xcode 7, with storyboard / autolayout, etc. (For completeness: I started at the beginning on the year on older versions of Xcode, etc.)
I have a a UINavigationController hierarchy and some View Controllers contain a single UIView which contain a single child, a UITableView. (I am choosing not to use UITableViewController, so suffice to say ... it is not an option.)
The problem: The tableview starts 64 pixels (status plus nav height) too low:
Now: I've had things working for some of my UIViewControllers containing a UICollectionView within a UIView but I achieved it (after lots of poking / prodding, and a while back) by a top alignment constraint from the top of the UICollectionView to the top of the Top Layout Guide. (Looking through my storyboard I some alignments and some vertical distances, but all to top of Top Layout Guide.)
I am looking for help understanding if I can do what I want, if the approach of constraining the top of the tableview to the top of the layout guide is correct, or if there is a better way.
Unfortunately, I cannot seem to repeat this (perhaps 'cos I've forgotten some key press combination jujitsu, or new Xcode, or collection != table, or something in my view hierarchy. (I've checked all segues are adaptive push, I've even deleted/re-built this VC since I had one model segue, just in case it was confused that this VC isn't in a navigation view controller hierarchy.)
If I control/drag to connect or select the two to align:
this is what I am offered - note no "align to top":
Note: Here are the table settings that (to my understanding) should be adjusting edge inset and scroll offsets correctly, and do appear to ('cos it is the only child of the top view, per documentation.)
Here are the frames after view did layout subviews:
The approach that I ended up using came to me when I spoke to #ProgrammingBonn and mentioned the frames. I saw that the primary UIView was position as I wanted, and so it (finally) dawned on me to align the top of UITableView to the top of the UIView.
(I suspect that much as I was building my own ViewController and not relying upon UITableViewController I had an over inflated view of this particular view within the hierarchy. It was a subview not a primary view, despite occupying all the screen real-estate.)
So, to be clear:
I selected the UITableView, then command/selected the UIView (the main one, and it's parent) and then used the "align" tool to top align those two.
Try unchecking the "Adjust Scroll View Insets" option.
I am not sure whether this will fix your problem but have you tried playing around with viewController.edgesForExtendedLayout?
See more info here:
Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7
I created a UIView using storyboard, set up constraints. When I ran the application, the interface looked fine. The view covered the entire screen as it was supposed to (I made the background color black so it's easier to see what's going on).
http://contentlibrary.sinaapp.com/View%20from%20Storyboard.png (I'm sorry I have to link images in like this, but the system says I need at least 10 rep to post images.)
However, when I tried to get the size of that view using myView.bounds.size. I got (600, 580), which is exactly the size that appeared in the storyboard's size inspector.
I created another UIView in code
var myView = UIView(frame: CGRect(x: 0, y: 20, width: 600, height: 580))
and added it as a subview to the top-level view. It appeared but it didn't cover the entire screen like the view I created in storyboard. Both the view I created in storyboard and in code have the same value in their .bounds.size, but they appeared to have very different sizes on screen. (This picture is the view created in code. See there is white space at the bottom of the screen.)
http://contentlibrary.sinaapp.com/View%20from%20Code.png
Another interesting thing is, if I replace the above UIView with a UIScrollView, after the scroll view zoomed, it will update to the correct size.
I added a UIScrollView the same way I added the UIView using storyboard. I tried to print its size inside the delegate method scrollViewDidEndZooming:withView:atScale:. It says (375.0, 647.0), which is the correct on-screen size for a view that covers the entire screen on an iPhone 6.
Judging from this, it seems that views that come out of a storyboard don't automatically update to the correct on-screen sizes.
So how do I get a UIView object created in a storyboard to update its size?
Sounds like you're checking the size too early.
Try to put your code in viewDidLayoutSubviews method and see if it's going to change.