Broken Auto-layout of UIButtonBarStackView within inputAssistantItem of UITextField

Originator:mmoore
Number:rdar://32355534 Date Originated:May 23 2017
Status:Open Resolved:
Product:iOS + SDK Product Version:iOS 10.3 (14E269)
Classification:Other Bug Reproducible:Always
 
Summary:
When using a UITextField whose inputAssistantItem won't contain any autocorrection suggestions (either it's a secure text field or it's autocorrectionType is set to UIAutoCorrectionTypeNo) it breaks auto-layout constraints after entering the background then entering the foreground again (hitting the home button and re-launching the application)

Steps to Reproduce:
* Run the sample app (single view application with one textfield) on an iPad.
* Hit the home button.
* Launch the sample app again.

Sample project is a vanilla single view app with one IBOutlet UITextField, this code is in the ViewController:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.aTextField.autocorrectionType = UITextAutocorrectionTypeNo;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.aTextField becomeFirstResponder];
}



Expected Results:
No breaking of auto-layout constraints associated with the UIButtonBarStackView in the inputAssistantItem.

Observed Results:
Breaking of auto-layout constraint associated with the UIButtonBarStackView in the inputAssistantItem with the following log:

TestKeyboardAssistant[37264:1029080] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x618000092980 _UIButtonBarStackView:0x7fcf05c0af40.width <= 0   (active)>",
    "<NSLayoutConstraint:0x6180000924d0 'UIView-leftMargin-guide-constraint' H:|-(15)-[UILayoutGuide:0x618000195470'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIButtonBarStackView:0x7fcf05c0af40 )>",
    "<NSLayoutConstraint:0x618000092570 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x618000195470'UIViewLayoutMarginsGuide']-(15)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x7fcf05c0af40 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x618000092570 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x618000195470'UIViewLayoutMarginsGuide']-(15)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x7fcf05c0af40 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-05-23 13:37:20.184961-0400 TestKeyboardAssistant[37264:1029080] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x6180000929d0 _UIButtonBarStackView:0x7fcf05c0a780.width <= 0   (active)>",
    "<NSLayoutConstraint:0x6180000917b0 'UIView-leftMargin-guide-constraint' H:|-(15)-[UILayoutGuide:0x618000195af0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIButtonBarStackView:0x7fcf05c0a780 )>",
    "<NSLayoutConstraint:0x6180000918f0 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x618000195af0'UIViewLayoutMarginsGuide']-(15)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x7fcf05c0a780 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6180000918f0 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x618000195af0'UIViewLayoutMarginsGuide']-(15)-|(LTR)   (active, names: '|':_UIButtonBarStackView:0x7fcf05c0a780 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

Notes:
This open radar could be related: https://openradar.appspot.com/25825137

Configuration:
This occurs in 2 scenarios:

1.  The textfield has it's autocorrectionType set to UITextAutoCorrectionTypeNo.
2.  The textfield is a Secure TextField.

In both cases the center UIButtonBarStackView would be empty (contain no autocorrect suggestions).  I suspect this may be the cause of the auto-layout issues.

The issue isn't present when you either disable the inputAssistantItem by setting the leading/trailing BarButtonGroups to an empty array or use a textfield with auto-correction enabled.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!