objective c - iOS 8 Keyboard Extension: Constraint Error When Call Bar Appears? -
i noticed when i'm on phone , greenish phone call bar appears @ top of screen, custom keyboard won't appear (it's if gets skipped). debugged , discovered it's constraint error.
here error in debugger:
*** terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'the layout constraints still need update after sending -updateviewconstraints <keyboardviewcontroller: 0x16dfbe30>. keyboardviewcontroller or 1 of superclasses may have overridden -updateviewconstraints without calling super or sending -updateconstraints view. or, may have dirtied layout constraints in middle of updating them. both programming errors.' *** first throw phone call stack: (0x2ab43c1f 0x382eec8b 0x2ab43b65 0x2e6300ef 0x2b7cb5b9 0x2e630203 0x2e0ef4e9 0x2b7cb5b9 0x2e0ef2c3 0x2e630487 0x2e29ba8b 0x2e0004d7 0x2da28a0d 0x2da243e5 0x2da2426d 0x2da23c51 0x2da23a55 0x2dff8965 0x2ab0a3b5 0x2ab07a73 0x2ab07e7b 0x2aa56211 0x2aa56023 0x31e4f0a9 0x2e0621d1 0x389cf9fb 0x389d1021 0x2b916635 0x33956065 0x33955d3b 0x33956099 0x37c7a4fd 0x3886eaaf) libc++abi.dylib: terminating uncaught exception of type nsexception
it's of import note never errors/warnings in either orientation or orientation alter when there isn't phone call bar. using next adjust keyboard's height 216 270:
- (id)initwithcoder:(nscoder *)adecoder { if (self = [super initwithcoder:adecoder]) { //prepare our keyboard's values self.portraitheight = 270; self.landscapeheight = 190; } homecoming self; } - (void)updateviewconstraints { //super [super updateviewconstraints]; //check if self.view exists if (width(self.view) == 0 || height(self.view) == 0) {return;} //remove previous constraints [self.inputview removeconstraint:self.heightconstraint]; //define landscape mode self.islandscape = !(self.view.frame.size.width == ([[uiscreen mainscreen] bounds].size.width * ([[uiscreen mainscreen] bounds].size.width < [[uiscreen mainscreen] bounds].size.height)) + ([[uiscreen mainscreen] bounds].size.height *([[uiscreen mainscreen] bounds].size.width > [[uiscreen mainscreen] bounds].size.height))); //update view height depending on orientation if (self.islandscape) { //readjust our keyboard's height self.heightconstraint.constant = self.landscapeheight; [self.inputview addconstraint:self.heightconstraint]; self.view.frame = cgrectmake(0, 0, width(self.view), height(self.view)); } else { //re-adjust our keyboard's height self.heightconstraint.constant = self.portraitheight; self.heightconstraint.priority = 990; [self.inputview addconstraint:self.heightconstraint]; self.view.frame = cgrectmake(0, 0, width(self.view), height(self.view)); } }
& here's viewwillappear:
- (void)viewwillappear:(bool)animated { //update our keyboard's height when view appears self.heightconstraint = [nslayoutconstraint constraintwithitem:self.view attribute:nslayoutattributeheight relatedby:nslayoutrelationequal toitem:nil attribute:nslayoutattributenotanattribute multiplier:0.0 constant:self.portraitheight]; self.heightconstraint.priority = 990; [self.view addconstraint:self.heightconstraint]; }
** note: width() , height() macros.
i using auto layout in xib. i'm not sure begin addressing this.
updatethanks helping debug @remus! i'm trying observe when device beingness rotated within extension on ios 8, updateconstraints method still not beingness called.
- (void)viewdidlayoutsubviews { [super viewdidlayoutsubviews]; [self.view setneedslayout]; [self.view updateconstraintsifneeded]; //i've tried [self.view updateconstraints]; instead } - (void)updateconstraints { nslog(@"check width"); //check if self.view exists if (width(self.view) == 0 || height(self.view) == 0) {return;} nslog(@"remove old constraints"); //remove previous constraints [self.inputview removeconstraint:self.heightconstraint]; nslog(@"define landscape"); //define landscape mode self.islandscape = !(self.view.frame.size.width == ([[uiscreen mainscreen] bounds].size.width * ([[uiscreen mainscreen] bounds].size.width < [[uiscreen mainscreen] bounds].size.height)) + ([[uiscreen mainscreen] bounds].size.height *([[uiscreen mainscreen] bounds].size.width > [[uiscreen mainscreen] bounds].size.height))); nslog(@"update view height depending on orientation."); //update view height depending on orientation if (self.islandscape) { //readjust our keyboard's height self.heightconstraint.constant = self.landscapeheight; [self.inputview addconstraint:self.heightconstraint]; self.view.frame = cgrectmake(0, 0, width(self.view), height(self.view)); } else { nslog(@"detected in portrait."); //re-adjust our keyboard's height self.heightconstraint.constant = self.portraitheight; self.heightconstraint.priority = 990; [self.inputview addconstraint:self.heightconstraint]; self.view.frame = cgrectmake(0, 0, width(self.view), height(self.view)); } } - (void)viewwillappear:(bool)animated { nslog(@"view did appear: add together constraint."); [self.view updateconstraints]; //update our keyboard's height when view appears self.heightconstraint = [nslayoutconstraint constraintwithitem:self.view attribute:nslayoutattributeheight relatedby:nslayoutrelationequal toitem:nil attribute:nslayoutattributenotanattribute multiplier:0.0 constant:self.portraitheight]; self.heightconstraint.priority = 990; [self.view addconstraint:self.heightconstraint]; }
let's seek calling functions within of viewdidlayoutsubviews
. can called separately within of of other constraint events (like updateviewconstraints
, etc.).
- (void)viewdidlayoutsubviews { [super viewdidlayoutsubviews]; [self setkeyboardconstraints]; } - (void)setkeyboardconstraints { nslog(@"check width"); //check if self.view exists if (width(self.view) == 0 || height(self.view) == 0) {return;} nslog(@"remove old constraints"); //remove previous constraints [self.inputview removeconstraint:self.heightconstraint]; nslog(@"define landscape"); //define landscape mode self.islandscape = !(self.view.frame.size.width == ([[uiscreen mainscreen] bounds].size.width * ([[uiscreen mainscreen] bounds].size.width < [[uiscreen mainscreen] bounds].size.height)) + ([[uiscreen mainscreen] bounds].size.height *([[uiscreen mainscreen] bounds].size.width > [[uiscreen mainscreen] bounds].size.height))); nslog(@"update view height depending on orientation."); //update view height depending on orientation if (self.islandscape) { //readjust our keyboard's height self.heightconstraint.constant = self.landscapeheight; [self.inputview addconstraint:self.heightconstraint]; self.view.frame = cgrectmake(0, 0, width(self.view), height(self.view)); } else { nslog(@"detected in portrait."); //re-adjust our keyboard's height self.heightconstraint.constant = self.portraitheight; self.heightconstraint.priority = 990; [self.inputview addconstraint:self.heightconstraint]; self.view.frame = cgrectmake(0, 0, width(self.view), height(self.view)); } }
objective-c ios8 autolayout nslayoutconstraint custom-keyboard
No comments:
Post a Comment