I'm going to get heat for posting this question that has probably been answered multiple times before, but I wanted to get a new understanding on how to incorporate Storyboards and auto layout into my app.
The whole thing is done, but I've used countless Xib files that don't even have a proper view layout to them. Everything related to image position and size is done through hard-coding CGRect(x,y,w,h) frames. I'm not using auto layout, and my Xib files are not populated with proper views (just temporary views to provide the IBOutlet connections).
What do I start with first? Auto layout or transfer everything to Storyboard? What documents/guides can I read to help me with this?
I'm using Xcode 7.1.2, and iOS 8.1.
All the Xibs needs to converted to Storyboards first, so that the entire app has all its Screen is reflected in the Storyboard.
Once this is done you should start implementing the Autolayout, by removing the hardcoding from the code and managing them via the StoryBoard scenes.
Related
I've been trying to figure out how to code up a launch screen that is not in Xib form. Reason being, I cannot for the life of me figure out how to do a decent job with Auto layout and constraint building. Please do not suggest that I pursue that course of action.
I was thinking of implementing a custom UIViewController (with a Xib to hold just a reference to the view controller instance) that I could set with a black background and 5 UILabel subviews. That Xib will be used as the "Launch Screen File". I have the necessary methods to make sure the labels always resize properly given different device sizes.
However, is that even the right way to go about it? I'm really trying to refrain from just creating a Xib and using that, or drafting up an image in Photoshop or something like that.
I'm designing an iOS app in Swift, not using auto-layout. I'm not using auto-layout because if i do, when my labels update, the design resets. For now, I'm designing for an iPhone 4.7 inch, but when i run it on the simulator for any other size device, the design is completely messy.
UPDATE:
I designed my storyboard with the proper constraints. I added my UIImages in the override func viewDidLayoutSubviews and positioned them outside of the screen. When a button is tapped, there should be a sequence of animations which are triggered as well as a UILabel which should have its value updated.
I commented out some code and kept running it to find the problem, and I found that the UIView reset whenever the UILabel updated. The values are being queried from Parse.com.
The design works when the label is NOT being updated. But once the value changes, the view resets...
I tried disabling auto-layout and it works. However, if I have auto-layout turned on it doesn't.
What do I do?
Thanks in advance
You should really use Auto Layout. It is the way forward for UI layout. The problem with your labels can surely be fixed with proper constraints.
Make sure you modify constraints instead of frames. The layout engine will calculate the new frames when needed, as helpfully mentioned by #rdelmar.
We're trying to get a new version of our app using Autolayout, size classes and trait collections (since that's what Apple seems to be pushing for). We may have the luxury of having the deployment be on iOS 8 and up only. However, designing the UI using IB is driving me crazy. We need a video player view slide down on a swipe down gesture at runtime. The video view was setup using IB and the constraint setup with autolayout that holds it in place seems way too stubborn. The view cannot easily be moved around at runtime. Wondering how folks have faced similar issues and how they split their design.
Use storyboad for layout or have the storyboard load a xib ?
Use one xib for iPhone5, iPhone6 and 6+ and another for iPad or use traitcollections and sizeclasses with one xib ? (This is proving to be rather difficult to tune)
The constraint visual format seems more cryptic than regex, and I'm tired of unsatisfiable constraints in the logs.
What combination of xibs, storyboards, autolayout, traits and sizeclasses have folks gotten best results with ?
I am currently going with multiple storyboards and have view controllers load xibs in the storyboards (in the hope of reuse for the xib)
One way to deal with this issue is to add properties to the constraints. When you want to slide the video view down then you do so by changing the constraints. Using this in conjunction with animations gives you the same smooth experience you would get by changing frames, etc.
Halfway through my project I realized that I shouldn't be using auto layout. The only problem is that when I disable it, I lose all of the images and such on my storyboard. Is there a way to keep all of the images and the IBOutlets/IBActions that I created, or will I have to do all of that over again?
So i'm learning how to use scrollviews and i've got one working successfully.
When working with an xib file, it's easy to work with a scrollview as I can put a scrollview on the background/ workspace and set the size, how I want my labels and buttons to sit on top of it etc and then when i'm ready, move the whole thing onto my View.
The project i'm currently working on uses storyboards and so I don't have the ability to put the scrollview on the workspace and get my size and arrangement right.
Is there a workaround? What's the best way to do this?
Thanks
You just need to add your scroll view to the view of one of the storyboard view controller's views, and then you can do the same things with it that you could do in a xib file. Also, even if your project uses storyboards, there's no reason that you can't have a xib file as well.