Tricertops/KeepLayout

keepLeftInset issues with iOS 11

Closed this issue · 5 comments

We have recently updated our project to iOS 11 and are getting some crashes due to keepLayout in the project as shown below:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Keep Layout: Calling keepLeftInset allowed only when superview exists'

In this case the code works fine on iOS 10 but breaks on iOS 11.

I have downloaded the latest version of KeepLayout and added it to our project but this still seems to be showing the same issues.

I noticed that you have recently pushed some modifications for the latest phone versions (safe spaces etc) and wondered if you had any idea what was causing this issue?

Simon

Yes, I changes some things related to insets, but not this assert. Do you have a superview on both iOS versions? Are you removing this view from hierarchy and then adding it back?

I think this commit might change some behavior. In past I had to swizzle a method to automatically remove the constraints, but today it works automatically.

I think deletion of this swizzling introduced a bug when view changes the superview. I’m going to fix it today.

However, I don’t know why your assert failed.

I pushed a fix, but this was not a cause of your issue.

Post more info about your failed assert, please.

Hi @Tricertops,

Sorry for the delay, Australian bed time.

To give some more details about the exact issue we have a UIToolbar with an array of objects inside it. The objects have been added to the UIToolbars item array:

`self.items = [NSArray arrayWithObjects:optionsItem, textItem, sendItem, nil]; `

All the buttons inside this now fail with the KeepLayout functionality due to the problem raised above.

It seems like it might be an issue with UIToolBar as previously we could set constraints on items inside the item array but now we can't.

In iOS 11 when we check the superview of an added item we get nil

In previous iOS versions we'd get an actual superview:

<BTextInputView: 0x7faccfde25c0; baseClass = UIToolbar; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x7faccfdb5c80>>

By the looks of it then it might be an issue with UIToolBar and its changing structure rather than a problem with KeepLayout.

Yep, that sounds like an internal change in UIToolbar. Try setting up the constraints later, for example in -viewWillAppear:. The UIToolbar is probably lazy to add them to view hierarchy at the line self.items = ... and waits until they are actually needed.