Nesting scroll views - ios

"It just works", or does it?
So I was going nuts trying to fit one ScrollView into another.
I get to the point when I actually made two separate xib files, did a scrollable label in one, and a scrollable image in another. Both are works perfectly in separate xib's.
After that I manage to open xib files as simple text(looks like they are formatted as XML or something similar) and simply cut scrollable image view(with all of superviews that I needed) into my main.(containing scrollable label)
So the idea was simple yet beautiful, I was like 90 percent sure it is going to work, because I inserted all the necessary view-scrollView-contentView stuff. And it is not. As you can see guys, image is big enough, views setted to be large and you can barely see tiny bit of it. So it SHOULD be scrollable, right?
Label with text keeps scrolling just fine, but the image wont move.
I was also trying to get scroll enabled via code, setting property to YES, but it wont help.
I also tried disabling auto-layout, thinking that it could be easier, but it was not much luck on the first attempt. Will be great to hear you guys thoughts, maybe I should disable auto-layout and try it out the old-way? Or is there a way to solve this puzzle as is?

Maybe my question was a bit long and not much of a readable, sorry for that guys, anyway I found my answer and will post a solution for any of you guys wondering about the same thing.
Just a reminder, I was trying to achive scrollable text+ scrollable image. Text should be scrolled up/down and the image should be scrolled in all directions.
So I find my previous attempt almost completely broken and started fresh(couple of times) and in the end I find the configuration that suits my needs.
Matter of fact, this particular configuration works almost exactly out of the box, most of the trick is get the right views in position. After that you just have to add missing constraints from the "Editor"->"Resolve layout issues" menu and get rid of few nonsense constraints that IB add god know why.(like those ones that adds 200pt blank space at the bottom or so)
After that you'll be pretty much set. If not, refer to the picture link, or github repo. Hope that will help someone.

Related

swift 4 and Xcode autoLayout and UIImageview as Button

I am working on auto layout and making those UIIMages as Button.
I would like to make those button to be clicked and switch the images
as well as showing some words in the label.
In this case what should I do?
In addition, as it is shown, the auto layout ratio is different only from the iPhone SE. In. this case What should I consider?
Many thanks,
The first thing you need to learn is auto layout. Start with basic Always go with Apple's doc first
This one I likes he is good and you will also find how to use buttons as image view, using card game example, check other tutorials also very helpfull.
Stanford university autolayout by Michel Deiman
As far, your question just gives your label Horizontal in the container constraints(open storyboard in the right bottom third from last (allin) click on it popUp will open), and 20 bottom to the buttons and it will be in the centre. Every elements need x,y height and width so it knows exactly where to place, so you also need to give constraints to the buttons, Learn stackView to understand how to place your button without giving many constraints to each button and stack view will handle it for you, try hide and show to one of the button and magically stack view will adjust all adjustment. I suggest before staring Do read apple's doc first.
And Your question is too broad to answer, so read and try adding different constraints based on your need and ask a specific question(after trying by yourself) like why this label getting cut what constraints should i add so people know exactly what you want to achieve, people are always ready to help, just ask the right question.
happyCoding

Embedding lots of views into a uiscrollview and have constraints match up? Is this possible?

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.
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.
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.

Xcode 6 switches being truncated on left (in a table view)

For some reason I cannot get all switches to display properly on a screen. Some of them appear to be overwritten on the left edge but from what I can determine all of the switches and text views are correct. Any suggestions are welcome
So first, to make sure that this is the problem: while your app is running, click on the two rectangles overlapping on the right of the Debug Area to "Debug View Hierarchy"
When you have that, rotate your views to make sure that in every row you don't have your text views overlapping your switches. That's what it looks like what's happening, but you can use this tool to confirm so.
If so, and you are using auto layout, make sure you are setting your constraints correctly. If not, then make sure you are setting the width properly. To prove it's an autolayout issue, you could temporarily hard code a length to every text view to see if the issue is still there. If that fixes it, than auto-layout is just making your textviews wider than they should be.
Good luck!

Problems with autolayout and resizable views

I have issue with autolayout.
I have three different views (could be n views as well). When I pin first one to top of super view and connect one next to the other everything seems fine. But if I want to change height of first one the other two does not follow (they stay on the same position). What I find weird about this is that if I connect only two views this works perfectly.
To have better understanding what I am trying to achieve I made simple, example solution with three views:
http://i.stack.imgur.com/cMwiB.png
So, when I set height of green view to 0 ( can be any other number as well ) and only red view is connected, this works fine, red will move as it should. Blue one is not connected and it remains where it is:
Here is screenshot when I connect blue to red:
What I tried to do:
connect blue one to green as well ( not working)
connect blue only to green ( not working )
"boxing": have boxes with views at the time ( ugly, hard to manage, not working in all cases)
What I would like to know:
what makes this happen? Can I change this kind of behavior?
What is the best practice to have flexible length for height (Besides UITableView)
Thanks in advance.
Ok, I think you're falling into the same trap I did, when I investigated autolayout some time ago. It's tricky to explain, but I'll do my best. When you work with autolayouts, you need to forget completely about setting a view's frame at all. And that, my friend, includes changing size and positioning. When you use autolayout, you define some constraints, some "rules", that the view tries to respect when rendering the screen, so the more specific the rules are, the less random will be the behavior of the view. I mean, if you just define the spacing between views, you're implying that the height of the views doesn't matter, so it's possible that some views grow or shrink when the re-layout is called (that is, if you don't specify a constraint for size. You probably want to always specify the size of some views in every layout...)
By the way, you're allowed to violate the constraints by manually changing the frame of an element AFTER a re-layout is called, but when the re-layout method is called again, the constraints will be forced so the size and positioning of the views will change. Quick tip: an easy way to force the re-layout method is to change orientation (command+left / command+right in the simulator).
So after saying that, I have to say that the layout you provided is completely working as intended, at least to me. When you change orientations the constraints you specified are ALWAYS being respected. If you want, you can try to apply some frame-setting in the viewDidAppear method, because this one is called AFTER the autolayout (and thus, you're able to violate the constraints temporally). After doing this, your view will be broken but once you change orientation the constraints should be respected again. Make sure it's that way.
From here I can only wish you luck ;) Oh, and refer to the documentation, it was a life saver to me when I looked at this half a year ago. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html It might seem a classic, but it's a pretty nice doc.
EDIT: one last thing. I have the impression that constraints are not designed to be dynamic. You define them once, and they're there always. Their main purpose is to ensure that subviews are rendered as intended in every screen resolution without fail, so if I were to make an application with moving views, I would leave them outside of the autolayout, or avoid using it at all. Just a personal impression though :)

Make UIScrollView scroll from scrolling inside OR outside of it

Say I have a UIScrollView that scrolls horizontally just fine. It's height is around 50px. After usability testing, a lot of people are trying to scroll the contents by panning outside of it. Here is the setup:
Where it says "Amount" is the scrollview
I am wondering if it is possible to attach a UIPanGestureRecognizer on the blurred background it sits on top of and have it scroll along with that as well. If this is possible, could someone give me a start on what that approach would possibly look like?
Nah, the simple solution is simply make the scroll view bigger .. it's just that simple.
Have it mostly transparent, with your content sitting where you want it.
What you describe in your question is a good idea but it's extremely! hard to really implement well, a total pain. You simply "make the scroll view bigger".
Nice looking app.
These may be relevant to you...
The UICollectionView "swipe-away" in iOS7 app manager?
Show/hide UIToolbar, "match finger movement", precisely as in for example iOS7 Safari

Resources