I'm going to explain my situation 1st so that the question is clear. I'm using a scrollview with images in it right now. Those images right now link to different views in a storyboard. Instead what I'd like to do is have that image open up a new UIScrollview w/ views displayed. These views are already in the storyboard of course without nibs.
So I'm essentially trying to display UIViews in a UIScrollView.. except I cant' initialize with nib (at least to my knowledge).
If you are looking for a place to setup your scrollview that is in a Storyboard use awakeFromNib.
Related
I am building an iOS app with multiple screens but I want avoid duplication of code as well as one large storyboard. Ideally I would like to load the various View Controllers based on a selected storyboard in my content view when needed.
The template of the screen (Master/Root View) shall be composed by 3 Views, namely:
View A that acts as a Navigation View,
View B where the various View Controllers should be loaded based on user actions and,
View C, much like a Tab bar or a 3rd View where I can display some
circumstantial information.
Now, of course I could go with a traditional UINavigationController and UITabBar but I need greater control over those views, notably in terms of size (they have minimum heights that are larger than the ones for NavBar and TabBar).
I also need those Views to resize based on the Traits and Class Size to keep filling the entire screen.
I am trying to use container views to doing so, but I can't get them to resize automatically despite having tried a different set of constraints in auto-layout. Putting the 3 views in a stackview does not do the trick either.
Ultimately I would like to be able to work separately on my various Controller Views that will be loaded in View B, using their own storyboards, calling them programmatically in B and having everything automatically resized.
Thank you all for your kind and valuable input!
Chris
When using addChildViewController(childVC) / addChild(childVC) (Swift 4.1 / 4.2), followed by myContainerView.addSubview(childVC.view) you need to either
add constraints for the added subview
or
set the frame of the subview and .autoResizingMask
After that, your newly added subview will layout and resize correctly.
subview
I'm currently stuck at making this freeform view follow AutoLayout/TraitVariation adjustments, so that it would look the same on every device. The view is contained in a separate .xib file. Somehow, pin and align tools are disabled. How can I refer to Main.storyboard. I wanna know if there's a way of making it follow superview (Main.storyboard) size using Interface builder.
I struggled with the same thing a couple of weeks ago and unfortunately, it seems there is no solution for that. I ended up with coping my XIB view into storyboard :(
In my app, I am using Storyboards. There are two ViewControllers in it. In the first ViewController, there are many different UIViews. UIViews are being used as screens. For transition from one view to another, I have written a UIView's animateWithDuration block.
In my Storyboard, I find it very difficult to set the UIView's content like Buttons, ImageViews etc. I have to hide all of the views and only then can I set the View which I want, as all of them are in the same UIViewController and same size too. And now with the Autolayouts, it becomes really difficult to set Contraints etc. Is there any convenient way to do so :
Create separate UIViews as XIBs and load and unload them programatically? Is it memory wise alright? Is it a good approach?
Can I do something directly in Storyboard? Like create UIViews and connect them to Storyboard instead of making one UIView on top of another etc? Create something like segue etc? As done to connect TableView's cell with "DetailedView" etc
Any other better approach?
I designed about 40 view controllers using a 5.5 inch storyboard layout. After all of that I tested it on the iPhone 4S...big mistake. everything is jumbled together being for a larger screen size. I was able to fix one view controller up using Size Classes. I am wondering if there is any way I can adjust all 40 at the same time, or at least avoid doing this for every single one. It is really frustrating finding this out now. Thanks!
This is a relatively complicated issue you are attempting to solve, but I have two potential solutions. Both suggestions are based on moving your current interface into containing UIScrollView instances
If you are using storyboards, then for each of your view controller scenes, put a UIScrollView as a descendent of the view controller's view. From there, provided your subviews are contained within other views (like a container view for a set of buttons), you can move those into your scroll view. You will have to setup constraints to define the size of the scroll view's content, but this will allow the size of the device to have a smaller impact on the interface as you will get scrolling as needed.
If you are using nib files (.xib) then it is essentially the same thing, but easier. In this case, move a UIScrollView onto the canvas, but not as a subview of the default view. Once that is out there, move the original view to be a subview of the scroll view and set constraints to be 0 from the subview to the scroll view. Finally, right click drag from the File's Owner icon to the scroll view and set that as the view outlet.
Hopefully one of these will help you.
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.