Pour kettle and let steep the gods of tea. @newsblur is my caffeine baby.
911 stories
·
755 followers

Stack View Constraint Conflicts When Hiding Views

1 Comment

The Stack View is a great timesaver when it comes to Auto Layout but it is not totally pain free. Having a stack view create and manage the constraints for you is great until something goes wrong. Debugging an unable to simultaneously satisfy constraints error is hard when you don’t know what the stack view is doing. A common cause of stack view auto layout conflicts is hiding views that have an explicit size constraint.

Creating a Conflict

I got a little lazy when creating a stack view for last weeks post on refresh controls. This is what I ended up (with some extra borders added to each view for clarity):

Stack view

The stack view is vertical with a fill alignment and distribution and some extra spacing between the four views (two labels, two buttons). To add some extra padding to the two labels I added a fixed height constraint of 128 points:

Fixed Height Constraints

To make it easier to debug I added an identifier to the constraint named OrangeLabelHeight:

Constraint Identifier

The UIStackView documentation hints of trouble ahead:

Be careful to avoid introducing conflicts when adding constraints to views inside a stack view. As a general rule of thumb, if a view’s size defaults back to its intrinsic content size for a given dimension, you can safely add a constraint for that dimension.

What is a UISV-hiding constraint?

I toggle the visibility of the orange button and label with a property in the view controller that changes the isHidden property of each view:

private var orangeAvailable = true {
  didSet {
    orangeLabel.isHidden = !orangeAvailable
    orangeButton.isHidden = !orangeAvailable
  }
}

This is what I see on the console when I hide the orange label (truncated for brevity):

Unable to simultaneously satisfy constraints.

"<NSLayoutConstraint:0x60800008c1c0 'OrangeLabelHeight'
UILabel:0x7fc178f092b0'Orange Membership\nFor som...'.height == 128
(active)>",
"<NSLayoutConstraint:0x60800008d930 'UISV-hiding'
UILabel:0x7fc178f092b0'Orange Membership\nFor som...'.height == 0
(active)>"

The conflict is clear. I have two constraints both trying to set the height of the orange label. My constraint OrangleLabelHeight wants 128 points and another named UISV-hiding added by the stack view wants 0 points. If we use the view debugger we can also see that both constraints have a priority of 1000 meaning they are required:

Constraint priorities

This suggest the way to remove the conflict. Lower the priority of my constraint to be less than 1000:

Priority 999

A better solution in this case would be to create a custom label view with the extra padding and remove the explicit height constraint. If you find you do need such constraints remember you can lower their priority to avoid conflicts with the stack view.

Sample Code

You can find the example layout from this post in the RefreshScroll project in my GitHub repository.


Stack View Constraint Conflicts When Hiding Views was originally posted 05 Dec 2016 on useyourloaf.com.

Want this direct to your inbox? Sign up and get my free iOS Size Classes guide.


Read the whole story
samuel
18 hours ago
reply
This comes up a lot on the Turn Touch Mac and iOS apps.
The Haight in San Francisco
Share this story
Delete

Please enjoy this Serrano’s Pizza commercial

1 Comment

Home of the most expensive slice in SF.

(Thnaks, Jess!)

Read the whole story
samuel
3 days ago
reply
The pizza joint next to NewsBlur HQ has their own dope beat
The Haight in San Francisco
Share this story
Delete

“I grew up in the suburbs. I used to think that I could write...

3 Comments and 7 Shares


“I grew up in the suburbs. I used to think that I could write a prescription for a poor man: ‘Get a job, save your money, pull yourself up by the bootstraps.’ I don’t believe that anymore. I was ignorant to the experiences of poor people. I’d invite anyone to come and meet the people who live in this neighborhood. Right now we are surrounded by working poor people. These are the people who sell your tools at Sears, and fix your roofs, and take care of your parents, and mow your lawns, and serve your meals. They’re not getting a living wage. There’s no money left to save. There’s nothing left if they get sick. Nothing left if their car breaks down. And God forbid they make a mistake, because there’s nothing left to pay fines or fees. When you’re down here, the system will continue to kick dirt in your face. You can’t pull yourself up when there’s nothing to grab onto. We aren’t paying our brothers and sisters enough to live. We want them to serve us, but we aren’t serving them.”

Read the whole story
samuel
4 days ago
reply
This whole HoNY series this month has been the first thing I read every day.
The Haight in San Francisco
popular
3 days ago
reply
ChrisDL
3 days ago
reply
New York
Share this story
Delete
2 public comments
codesujal
4 days ago
reply
This election, summarized with more left-leaning vocab. Right-leaning vocab might be different, describing the same thing.
West Hartford, CT
jhamill
4 days ago
reply
"You can’t pull yourself up when there’s nothing to grab onto."
California

Link: Reducing Bias

2 Comments and 4 Shares

It can be tempting to paint all of Donald Trump’s supporters with the same brush. After all, it’s tremendously disheartening that so many people were willing to ignore the racist, sexist, bigoted aspects of Donald Trump’s agenda. However, a willingness to overlook is not the same as more than 60 million people who voted for Trump being as horrendous as he is. Proceeding as if that were the case is both inaccurate, and counter-productive.

Instead, it’s useful to understand how those of us who hope to see Trump’s agenda defeated can persuade others to join the cause. Insulting them won’t do it, but listening to them just might.


∞ Permalink
Read the whole story
jprodgers
4 days ago
reply
Click on the "listening to them" link, solid article.
Somerville, MA
samuel
5 days ago
reply
Single greatest article I've read all week. (The 'listening to them' article)
The Haight in San Francisco
kazriko
5 days ago
Yep, and something that I've seen over and over again on the writings on the other side.
kazriko
5 days ago
Here's a similar argument from the other side. https://accordingtohoyt.com/2016/11/29/fighting-with-words/
Share this story
Delete

Arrival

1 Comment


Arrival

Read the whole story
samuel
5 days ago
reply
👏
The Haight in San Francisco
Share this story
Delete

Shy Person’s Guide to Calling Representatives

3 Shares

actionfriday:

In the coming weeks and years you will be seeing a lot of requests to call your representatives about issues facing our country. But maybe, like me, you hate calling people SO MUCH. This is a guide for you.

I’m anxious on the phone. My blood pressure rises when I need to call a customer service line, or even just ask the hours at a restaurant. So calling representatives about political issues is one of my least favorite things to do. I posted on Facebook recently about my experience calling my reps and it got a good response. I think there are a lot of us who want to pitch in but hesitate to pick up the phone. With that in mind, here is my shy person’s guide to calling your representative.

BEFORE YOU START:

* Pick an issue. This week I suggest calling to oppose the incoming administration’s cabinet picks:
White nationalist Steve Bannon for chief strategist
Climate change denier Myron Ebell for EPA Administrator
Jeff Sessions, who has a history of racist comments and voting, for Attorney General
Islamophobic Michael Flynn as NSA advisor

* Know that it’s FAST. It takes maybe 2 minutes to call one person, including the time it take to look up their phone number. Think of it like ripping off a bandaid.

* Know that you don’t have to be persuasive. You are really just calling to put yourself on a tally that will be passed along to your representative. You don’t have to convince anyone and no one will try to argue with you. Just say your piece (as awkwardly as you want! they won’t care!) and get off the phone.

* Know that calling is better than emailing. I would much prefer to email, but your message is more likely to get lost in the deluge. When you talk to a staffer you know for sure that your opinion is being recorded.

* Find your reps’ numbers. Go here or here to find out who they are. Call their local lines when possible. Write down the numbers or save them as contacts so you don’t have to look them up every time.

* Take a deep breath.

DURING THE CALL:

* Start with an introduction. I use: Hi my name is _____ and I’m a constituent of Rep./Sen. ____ calling about a concern I have. I see many scripts that omit how to start the call, and it helps me to know for sure how to begin. Be sure to say you are a constituent. They might ask for your zip code, so have that ready.

* Have a script. This is 100% the best way to keep you focused and calm. There are lots of good scripts you can use here or you can write your own. Say what you are comfortable saying. Remember, you are just calling to be counted.

* Expect their response. The thing I see missing from most instructions for calling reps is what to expect in their response. Most of the time they will just tell you they will pass on your concern. Congrats - if they do this then you are done! They might read a prepared statement in response. They might even say that your rep is not going to take action on the issue you brought up. What they WON’T do is argue with you or say, “what a stupid thing to be concerned about.” Don’t let your anxious brain convince you they will do this.

* If necessary, reiterate your request. If they read a statement or say the representative will not take action, don’t get flustered. Just say, Once again, I’m calling on the Rep./Sen. to _____. 

* Thank the staffer and hang up.

AFTER THE CALL:

* Take another deep breath.

* Congratulate yourself.

* Do some self-care. Maybe start here. Or here. Do whatever makes you feel happy and rewarded.

* Know that it gets easier. The more you call, the more you know what to expect. You may even get to know some staffers. You might never like calling but I promise it gets less awful.

Read the whole story
jprodgers
7 days ago
reply
Somerville, MA
samuel
7 days ago
reply
The Haight in San Francisco
Share this story
Delete
Next Page of Stories