2

So, here's the basic idea. I have a view with tons of subviews, they all use AutoLayout. I need them all to scroll up to be seen, so I go to embed in uiscrollview and... everything is off. This app isn't using size classes, just one Any Any type.

I went to embed in a view instead and also, the constraints do not adjust for the new view, and its 20 extra width/height in pixels.

I'm betting this is like Scrolling Right on your air to view asset catalog imgs, it's simply impossible, but wanted to ask. If it is impossible, shouldn't this be a bug report. I'm used to embedding, then editing, and tearing down/rebuilding xibs, but with all the hype around it, I keep thinking this new feature should make it easier, not harder, so I think I'm missing something basically.

I did search and there's lots of questions from people who haven't embedded anything before, but I didn't see anything for 2 or so views already being in the new embed + NSLayoutConstraints now getting completely wiped, it's relatively complex so me, not knowing the design, has to go memorize all 40 or so relations and remake it, or maybe just trust the "set frames to new view", but that probably won't turn out right since I have to make the view 20 pixels smaller each side, to counterbalance embeds

Thanks for any help. Shortcuts, tools welcome.

6
  • Shortcut = UICollectionView? FlowLayouts.
    – iphonic
    Jun 17, 2015 at 8:53
  • The view has a bunch of various text fields, labels, images, etc. UICollectionView doesn't make sense
    – Stephen J
    Jun 17, 2015 at 9:07
  • 1
    I realize I pointed out that apple has yet to finish functionality, and voting me down won't change that. In fact, voting me down won't change the fact that this question hasn't been asked before, and I don't care about rep, I just want a solution, so ask me to clarify any confusion before hitting the down arrow. I'll be happy to help and make a sample xib and ask you to solve this. (you being generic, not talking to "you" specifically)
    – Stephen J
    Jun 17, 2015 at 9:09
  • 1
    I think CollectionView is good idea to use, as you must be otherwise designing the ScrollView, or adding small components into it, why not do this using UICollectionViewCell?
    – iphonic
    Jun 17, 2015 at 9:39
  • Hmm, it won't handle the resize for various types, but you did make me realize, the view itself mostly has linear flow, so a table/uic might happen to work, however is an edge case. Thank you!
    – Stephen J
    Jun 17, 2015 at 18:21

2 Answers 2

8

I figured this out. I was like "Well, I'll just embed the main View Controller's view into a subview", but nope, that's not allowed.

So I copied and pasted the head view into itself, deleted the originals, then embedded that one-layer-deep into a UIScrollView and manually set the size back and origin back to 40 pixels less each side, and 0,0 for x, y.

I have to re-hook up all the outlets but this is much easier than anticipated.

As a side note, it's still impossible to view [right side of] asset catalog on an air (without toggling off all sidebars), but it's not impossible to quickly do keyboard add/edits.

3
  • Did you find any other solution? it's absurd that Apple doesn't provide a solution for this kind of issue... every time adding a scrollview is extremely tedious and over complicated.
    – MatterGoal
    Feb 15, 2016 at 17:55
  • No, I think it's a combination of the original product being a new one, eg: not knowing the design to begin with, so they say "Why didn't you just do it from the beginning?" and my last paragraph is confusing, they might think my "complex" statement means I don't understand, when in truth, I mean there's a crap-ton of NSLayoutConstraint outlets. I have lost faith in Apple by now, so I just deal with their interns coming from JavaScript and writing industrial-level tools. We live in a world where scissors and single-colored paper is the inspiration for design, just like 2nd grade. Shrugs.
    – Stephen J
    Feb 16, 2016 at 19:10
  • 2
    I always find myself coming back to this post from time to time. Real self-sanity saver! Feb 29, 2016 at 5:39
0

To answer the question, yes its possible. Use autolayout with scrollviews you need to have a content view set inside the scroll view which has the same size and width of the scrollview. With constraints bounding its size left, right, top and bottom.

Then add the subviews to the content view. This will make the scrollview height much easier to manage.

3
  • This is not the case, imagine you have a bunch of views inside a view. One's a text view at the bottom, and suddenly you need all of them to scroll up to see the textField. So you embed them in a scroll view. I've done this many times without autolayout. But now, you have a bunch of broken constraints, since they aren't auto-translated
    – Stephen J
    Jun 17, 2015 at 18:28
  • 1
    i have done this scenario you described a few times. Its quite hard to add a scrollview retrospectively and expect the constraints to work. Sometimes its easier just to clear the constraints and start again. Constraints are not auto translated. If you add a new view behind them they will always break as the point of reference has changed.
    – Christian
    Jun 18, 2015 at 9:59
  • I just got it, hyper simple, takes some work-around, posting in a sec.
    – Stephen J
    Jun 26, 2015 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.