Disabling Auto-Layout in One View messes with screen - ios

I am trying to disable AutoLayout for one exact view called conversationVC.
As it is a chat and I got the code from a project which is not using Autolayout.
My idea was to use
self.view.removeConstraints(self.view.constraints)
self.view.translatesAutoresizingMaskIntoConstraints = true
to remove AutoLayouts constraints and add my own ones from CGRectMake
For some reason the screen gets messy.
This is my view hierarchy:
This is what the screen looks like using no code at all to remove AutoLayout:
Now trying to remove and Autoresize all single Items in my View it looks like this:
As you can see certain views become missing.
Any idea how to overcome this behavior?
note: add button is in the correct position.
Edit: It is not a duplicate since it addresses the whole view and it's elements other than a single label. also i don't think Autoresizing is the problem, but something else

Related

Label in cell positioned in the very upper-left corner?

It's very odd - my cell labels are looking something like this:
However my constraints are set as such:
If I remove the constraints completely, then it's working. But I tested on multiple platforms and on both the simulator and an actual device. I've tried multiple combinations of constraints, none of which seem to work. This hasn't happened to me before, albeit I haven't done much iOS programming in a while. Is there something obvious I'm doing wrong or new in XCode 9?
Edit: I was able to fix by deleting and adding back a new UITableViewController and recreating it, but it's very odd and I'm wondering why this could be in the first place.
Check the custom class for your Content View, one level below your cell. If the Content View is a subclass of UITableCellView instead of UIView, you'll see this behavior. Unless you're sure you want to create a custom class for the Content View versus the cell itself, make sure not to use a Custom Cell here, in which case your Custom Class for the ContentView will be set to UIView.
Apply this constraint on label

Placing views and elements within Scroll View

So I'm trying to get a layout to work using Scroll View.
Correct me if I'm wrong but from what I've been reading around the internet, it looks like to properly use Scroll Views and make it work with AutoLayout you need to have your root view, then put the scroll view inside it with constraints binding it to take the whole size of the root view (left/right/top/bottom constraints to 0) and then adding a view inside the scroll view and once again binding it to take up the whole space.
Afterwards, any ui elements or subviews would go in the innermost view.
My problem is that often I have experienced issues while settings my constraints within the scroll view where for example setting a trailing constraint to 0 wouldn't actually set to the end and so on, the numbers just wouldn't add up. In this case when I'm trying to make the innermost view take the whole space,it ends up messing it up more than anything; see image below.
Any help would be appreciated.
I just created this layout using the follow:
To test it, I added an image view to the content view and put a humongous image in it. It scrolls around quite nicely including bounce etc.
Update: You need to select your ViewController and uptick "Adjust Scroll View Insets"
Hope this helps.

iOS Swift stackview inside a scrollview with constraints

I'm still getting familiar with iOS and the use of constraints. Initally had my layout setup with some constraints. But I ran into an issue. When entering text, my text fields are covered by the keyboard. I found some Apple docs: Doc One, Doc Two stating I should use a scrollviewin this case. It sounded easy enough but every time I put the content in the scrollview things go nuts. I've tried adjust my constraints in several ways, but nothing seems to help.
Anyone have any insight on what I'm missing?
Thank you
Before adding the Scrollview
After adding the Scrollview
If you use a UITableView with static cells and make your view controller a subclass of `UITableViewController, you don't need to worry about the keyboard. The table view controller takes care of keeping the focussed text field visible above the keyboard:
I wrote no code for that demo. It's all done in the storyboard. Here's the storyboard outline:

Interface builder position off screen

I have a container view showing a sidebar which is pinned to the main views leading edge. The sidebar is initial visible which is fine for iPads however I would like it to be hide initially for smaller devices. To do that I need to set the side bars trailing edge constraint to be (0 - its own width)
As far as I can see this is not possible in the interface builder. I have tried to do it in the viewDidLoad, checking if the device is an iPhone before doing self.sidebarX.constant = -self.sidebar.frame.width. This fails because viewDidLoad has not set up the views yet so the width is wrong. I also tried to do it in viewDidLayoutSubviews however the user sees the sidebar disappearing which isn't nice. I am sure there must be a common way of dealing with this?
I finally worked it out. viewDidLayoutSubviews was the correct place to be doing this. At first when I tried it, it was showing the sidebar slide away as the view controller loaded. It turns out this is because I was calling my closeSidebar method which animates the side bar moving off screen. Changing this so it just sets the view off screen and adding a check to ensure this only done once on first load (as viewDidLayoutSubviews is called multiple times) does the job of hiding the the sidebar for certain devices without anyone seeing it happen.
You can set this using xcode adaptative layout:
You can set the different position for all different screen types here, changing the constraints, positions, sizes to each different type you need.
You can install the layout of one object in different screen types using the dialog below:
Have a look in this 2 parts tutorial from raywenderlich part 1 part 2

iOS: How can I prevent a resized view from resetting itself?

I'm using ECSlidingViewController. When the app starts, it opens a scroll view which is resized dynamically, since it contains both labels and a table view. Both the table and the scroll view containing it are resized.
Everything works as intended when the view is first loaded. However, if I open and close the menu view, or if I use it to go to any view which resizes itself, the resizing does not work. Instead, it displays the scroll view as if it has the height assigned to it in the storyboard.
I'm completely lost as to why this happens, and would greatly appreciate help. I can post code as well, of course, but I don't know what code might help, since I guess that the error is on ECSlidingViewController's part.
Are you using auto layout? If so, whenever something else happens that triggers the application of the constraints, all the frames will be reset to the values dictated by those constraints. Try turning off auto layout and see if that fixes it. Refer to your auto layout settings.
Alternatively, if you want to keep auto layout, I'd generally suggest changing the frames by programmatically changing the constant values of the constraints. But, I'm not familiar with ECSlidingViewController, so I don't know if that's a reasonable option in this particular case.

Resources