4 ms·
Seriously, is autolayout actually used by a lot of people? I tried doing something semi-complex a few weeks back and I spent hours fighting with it. Then I sp
by mazerackham 12y ago
Seriously, is autolayout actually used by a lot of people? I tried doing something semi-complex a few weeks back and I spent hours fighting with it. Then I spent 10 minutes writing 10 lines of code and it worked.
When you finally grok it, does it become worth it?
- smackfu 12y agoWell, it's certainly encouraged by Apple, and it's getting to the point where they aren't interested that "supporting all these sizes without using AutoLayout is hard."
- orbitur 12y agoHow do you optimize for 3 different device sizes? Hardcoding it?
- archagon 12y agoYou can perform manual layout in the layoutSubviews method of any UIView. Simply calculate your positions with the current view size in mind, looking up the Size Class if necessary. (And don't use exact pixel positions, obviously.)
- ortuman 12y agoOf course it does. I admit it can take a few long to get used to it, but once you do, turns out to be kind of a mechanical process that saves you a lot of time. Above all, when combined with the interface builder. I'm quite sure those 10 min. wouldn't have been more than just 5 using IB + AL.
- archagon 12y agoI recently learned and used Autolayout to design a few different apps. It has its pros and cons. For relatively simple UIs, it's great, especially if you use Interface Builder. It really lets you express what you mean when you lay something out, and it automatically works with all screen sizes. On the other hand, if you're doing anything that requires lots of little views laid out in an orderly way — a keyboard, for instance — it's more trouble than it's worth. I think for Autolayout to have more general appeal, it needs two things. One, an easier way to use it programmatically. (Creating NSLayoutConstraints all the time is annoying.) And two, a better way to define equal spacing between views. (Creating spacer views is incredibly boilerplate-y.) Also, the more constraints you have, the harder it gets to conceptualize things like intrinsic contents sizes, priorities, and inequalities.
- emkman 12y agoHave you tried Masonry? It might be right for you if you want easier programatic use than NSLayoutConstraints provide. https://github.com/Masonry/Masonry https://github.com/Masonry/Masonry
- ggamecrazy 12y agoOnce you "get" doing AutoLayout you will never want to go back. I'm speaking as a guy who swore up and down to frames. All it takes is doing some adaptive stuff for 3.5, 4, 4.7 and 5.5 inch screens to make you want to jump out your window. By the time you create a good system to get the frames to work with an adaptive layout, you just implemented a poor man's version of AutoLayout. Just my $0.02. I think it saves me a lot of time. I try to avoid AutoLayout in IB and just use code, either a third party DSL or apple's own visual format language.
- acmecorps 12y agoHow do you do animations with autolayout? Isn't it kinda hard compared to frames?
- solomone 12y agoIt's actually easier depending on the animation you want to do. You can set an NSLayoutConstraint to an IBOutlet and then change it's constant in an animation block.
- weixiyen 12y agoyou can just set the constraint constant. I'd say it's much easier.
- ggamecrazy 12y agoYou just have to store the constraint in your VC or custom view. You still need to use frames sometimes though. I have found that scrollviews and AutoLayout are arch-nemesises.